How to bypass the controller in CodeIgniter?

I use the CodeIgniter framework for PHP and I like it, but I notice that a view is required for each view. I am wondering if there is a way to call a specific model from the view itself, and not route through the controller. I understand that in most cases using a controller is best practice, especially when the data from the model needs to be changed in some way, but I have cases where I just need to make a strict transfer of data to the view (which is loaded via ajax), and setting controller for this seems redundant.

Any thoughts? Thanks in advance!

+3
source share
7 answers

You fundamentally misunderstand MVC, at least as implemented in CI.

All URLs of your site (at least those that use the CI infrastructure) are displayed in functions (methods) inside the controllers.

http://myCIsite.com/controller/method[/var1†[/var2] ...

It doesn't matter if the URL is accessible via plain HTTP or through AJAX. It is always a one-to-one mapping. Because of this, you should think of the controller / method combination as a "web page". Do not think about presentation as a web page.

Models and views are subordinate to controllers. The controller delegates certain responsibilities to them - interacting with databases for models and displaying the page in views.

, /. , , , , , /, . , . , , ( () , / ).

, /. . , , , . (, , / .)

, CI MVC. HTML , CI . , , DRY .

, "-" /. /.

+3

, , .

, , CI , .

, , MVC. , .

0

, . , , , . , ?

, .

0

Ajax, URL/ javascript. , "" ; URL- . , , 3-4 .

URI URL- , . "ajax" .

ajax jquery -

$('#prod_img').load( "http://domain.com/ajax/get_img", {'color': 'blue', 'url_title': 'bla' } )
0

, , , , . , db , .

MVC, , Codeigniter .

0

MVC. , .

, , $this- > db . , .

0
gdfsg dsfg

s dfgdfg3 sdfgdsfg

dfgsdfg fdg dfgfd3 dfgfg enter image description here

0
source

Source: https://habr.com/ru/post/1754825/


All Articles