I'm creating an ebay-style (but more simplistic) shop in CodeIgniter and I'd like to know the best way to handle the items code/controllers.
At the moment, I've got a Category controller which is the main controller (in routes). /category/id is supposed to show a list of items for a specific category, and /category or / shows all items.
The category index($id=0){} in the controller loads the category helper which generates the category listing, then I echo it out in the view.
Now I'm up to the stage of adding the items aspect... Users need to be able to add items, view specific items, and the category code needs to be able to show all items or a specific category of items.
I was thinking of having a items controller with add_item, view_item, however now I'm wondering how I should be fetching the category listing from within the categories controller.
Should I have a items helper that loads the items model, fetches the list of items based off the category, assigns the list to a variable and echos the list? And when a user wants to view a specific item it loads the item controller view_item, and for adding add_item etc?
I also want the categories to display whilst they're viewing an item, so if I do it this way I'll also need to load the category helper within the items controller... Is this bad practice due to code repetition?
In short, here's what I would do.
It's normal to reuse your models across your controllers. It would be scary otherwise; it would mean a lot of code duplication. It's also normal to reuse your helper as much as possible. That's the goal of an helper! To implement a function that is reused at a lot of places. When you start to do copy + paste of the same lines, that's when you are not doing reuse. Create a function and reuse it.
Keep in mind,
Hope this helps.