[SOLVED]How should I use my Model(s) ? |
[eluser]julien.1486[/eluser]
Hello ! I'm a newbie in MVC conception and I have a problem with my application. I'm writing a small application in which users suggests me to add new features to the website. I have two tables in my database : category and features. category : id (primary key) int, name varchar(50) feature : id (primary key) int, name varchar(50), description text, status varchar(50), idcat (foreign key to category.id) And I would like to have this kind of result for instance, in a view : Code: - Blog How should I organize my code ? I have this model but I think it's not the good way : Code: class Category extends Model And my Controller looks like this : Code: class Roadmap extends Controller How can I pass to the view the categories with THEIR features ? Should I write a features model too ? Or should I add a private member $myFeatures as a array ? (But I can't keep the getAll() function : logicaly a Category cannot retrieve all categories (it's rather a collection's function). It's the first time I use the MVC design patter and my brain is not formatted yet ! Thanks a lot for your help
[eluser]julien.1486[/eluser]
Self-reply : Finally I was in a wrong way. I make a Model for each table in my database, except for the one including a foreign key (well, I just have two tables for the moment ). I've added private members to my class and a array named 'myFeatures'. When I retrieves the datas from the database I fill 'myFeature' with the result of a query build by using $this->db->get_where(....). This is described in this topic (thanks to the authors and to the helpers) : http://ellislab.com/forums/viewthread/88156/ I look for this all the day !
[eluser]thurting[/eluser]
Tell them to undress and proceed to take pictures.
|
Welcome Guest, Not a member yet? Register Sign In |