Send data from Controller to View or have logic within View? Send data from Controller to View or have logic within View? codeigniter codeigniter

Send data from Controller to View or have logic within View?


Yes, The controller takes care of communicating with the model and handling the data, the view takes care of presenting the data.

Make the data available to the view from the controller, in the most simple form, lets say a simple array.


Not familliar with CI, but if you have some kind of ActiveRecord or ORM, then add a getAllSubCats() method to the category(?) entity and call it when you loop through categories.

If the above doesn't make sense: View shouldn't even know a database exists, so to answer your question, do it in the Controller. Or better yet, do the fetching in the Model and pass the results back into the Controller.