08-20-2008, 06:25 AM
[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 :
How should I organize my code ?
I have this model but I think it's not the good way :
And my Controller looks like this :
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
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