Bruno
Bruno

Reputation: 37

model calls in CodeIgniter

Can we make model calls only from controller? I make model calls from view also, is it wrong to do so. Please suggest me.

Thanks.

Upvotes: 0

Views: 94

Answers (2)

He Hui
He Hui

Reputation: 2236

The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page. http://codeigniter.com/user_guide/overview/mvc.html

http://www.tonymarston.net/php-mysql/model-view-controller.html#together

In the MVC structure, the Model is the part that deals with data/database, view are designs/layouts, and controllers are the intermediary between the model and the view.

To answer your question, the Model and the View should never be directly connected in any sense. CodeIgniter may allow you to do so, but it is not what MVC is made for.

You may want to read a little more about MVC structure as a whole

Upvotes: 0

Robin Castlin
Robin Castlin

Reputation: 10996

Well although it's possible, it's really encouraged to do this from the controller and pass the data to the view.

Why? Because heavier calculations such as database request will make the site load funny.

You might first load opening of page, then menu, then the contest takes half a second to pop up due to query being run inside rendering, and not before.

So basic practice:
Let the controller run the heavy stuff, and render the view file simply with given data and avoid rendering too much of it's on.

Upvotes: 4

Related Questions