Handle object in class helper - Best practice |
I made this class for categories:
PHP Code: class Categories Then in controller: PHP Code: $categories = new Categories($this->categorii->entries()); So in my class I get the number of the items for each category. Is this the best practice?
i'm not so sure about your way of doing things
i think in general you should avoid calling models within your objects because objects needs to get filled by a model and the model should return the prepared objects to the controller a Library can do that but in this case i think a library is a wrong approach - you need a category wrapper object or something like this
Like you told me in this post http://forum.codeigniter.com/thread-63496.html ?
I was thinking, wouldn't be more practice if I join the categories table with products and count the products? And no more foreach and count method needed.
EDIT This was the best solution: PHP Code: function entries() {
Or I can use query cache, and on every ADD/DELETE delete cache and rebuild.
|
Welcome Guest, Not a member yet? Register Sign In |