0
votes

I've only just started learning CodeIgniter, so please excuse any misunderstandings I have.

I understand that the controller calls models and views. Views contain the HTML, models contain the database functionality etc.

I don't want to have to write code out to create a header menu, footer menu, side menu etc, in each of the controllers that import the menu structure into the view, so after some googling, it would look like it would be best to write a library in which my controllers can call to retrieve the type of menu they want.

My question is: Would I place my database queries for retrieving the data to build each menu in the library itself, or would I delegate it to a model and call the model from the library? For the menu construction, I don't need to write to the database, just read the data it contains.

Many thanks

1
Use codeigniter template library. In you can call all your database querys there. - vijaykumar

1 Answers

1
votes

I never put any query directly in the library, as I believe that goes against the MVC that CodeIgniter intended.

I would aim to always make functions for simple database queries in the model, so that you may re-use them in various other portions. This allows you to return the data from what you need via the database when you require it. Which in turn allows you, in the library, to add additional caching or manipulate the data as it comes from the model.

I based that from 3 years of working in CI, and this little picture on this page: http://ellislab.com/codeigniter/user-guide/overview/appflow.html