• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED]How should I use my Model(s) ?

#1
[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
|------ Add an article (done)
|------ Delete an Article (not yet)
|------ etc....
- Members
|------ Add a sign-up (done)
|------ Sending a confirmation email (done)
|------ etc....

How should I organize my code ?

I have this model but I think it's not the good way :

Code:
class Category extends Model
    {
        function Category()
        {
            parent::Model();
        }
        
        function getAll()
        {
            $query = $this->db->get('Category');
            return $query->result();
        }
        
        function getFeatures($index)
        {
            $query = $this->db->get('Feature')->where('idcat', $index);
            return $query->result;
        }
    }

And my Controller looks like this :
Code:
class Roadmap extends Controller
    {
        function index()
        {
            $this->load->helper('html');
            $this->load->model('category');
            
            $data['categories'] = $this->category->getAll();
                        
            $this->load->view('roadmap', $data);
        }
        
        
    }

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


Messages In This Thread
[SOLVED]How should I use my Model(s) ? - by El Forum - 08-20-2008, 06:25 AM
[SOLVED]How should I use my Model(s) ? - by El Forum - 08-20-2008, 06:08 PM
[SOLVED]How should I use my Model(s) ? - by El Forum - 08-20-2008, 07:29 PM
[SOLVED]How should I use my Model(s) ? - by El Forum - 08-21-2008, 02:19 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.