[eluser]Bartolo![/eluser]
Hi guys!
this is my first post here and i want to let everybody know that codeigniter rocks! ...but you already knew that ;-)
okay...my problem:
i got a dropdown menu that comes out of the database, i got it working, but as you can see there is an function inside the view. thats off course not what i want.
is there anyone who can help me rebuild this so i have the functions on the place where they belong?
Code:
TABLE 'insurance_categorie'
- cat_id
- title
- info
Code:
TABLE 'insurance_item'
- insurance_id
- cat_id
- title
- link
- info
Model
Code:
function getMenuCategories() {
$query = $this->db->get('insurance_categorie');
if($query->num_rows() > 0){
return $query->result_array();
} else {
show_error('Fout! Geen menu items opgehaald.');
}
}
function getMenuItems($cat){
$this->db->select('*');
$this->db->from('insurance_item');
$this->db->where('cat_id', $cat);
$query = $this->db->get();
if($query->num_rows() > 0){
return $query->result_array();
} else {
show_error('Fout! Geen menu items opgehaald.');
}
}
Controller
Code:
$data['menu_categories'] = $this->Mainmodel->getMenuCategories();
View
Code:
foreach($menu_categories as $menu_categorie):
echo "<li class=\"level1-li\"><a >" . $menu_categorie['title'] . "</a>";
echo "<ul class=\"sub\">";
foreach($this->Mainmodel->getMenuItems($menu_categorie['cat_id']) as $submenuitem):
echo "<li><a >" . $submenuitem['title'] . "</a></li>";
endforeach;
echo "</ul>";
echo "</li>";
endforeach;