Welcome Guest, Not a member yet? Register   Sign In
Model, helper or library
#1

[eluser]Unknown[/eluser]
Hi! I'm trying to develop a web directory in CI. It's my first time in CI and i have the folowing doubt:

Somewhere on the left side is a box with the directory categories. This entities (the categories) are stored in a database table. I created a model
for this entities, which has some methods like select data, add, edit, remove, etc. But i don't know where to include the function that generates the menu.

1. Should it be a helper?
2. A method from the "categories" model?
3. Should i make a "categories" library with methods like categories_menu(), featured_categories(), etc.
4. Or a special method in the controller prefixed by underscore, using views, and called by the active controller method to fill the left side?

It works in all theese different ways, but i'm asking you which is the right one from the MVC point of view, and specialy from the CI point of view.
#2

[eluser]Zack Kitzmiller[/eluser]
I would load the data from the model into the controller, then pass the data into the view.

If it get's quite a bit more complex, perhaps a library would be in order.

Correct me if I'm wrong guys.
#3

[eluser]Jondolar[/eluser]
A model is a representation of your data. Your data is the list of categories. I recommend you use a function in your model to extract the data from the database. Use the controller to pass it to your view.

Good luck with your project.




Theme © iAndrew 2016 - Forum software by © MyBB