[eluser]GioMBG[/eluser]
Hi ALL,
newbie ci
I just start to make my first SIMPLY application to compile the menu of my new web 2.0 control panel,
only to ask if is plausible use the MCV as is or if I have to make better my assemble.
controller:
Code:
class Site extends CI_controller{
function index() {
$this->load->model('data_model');
$data['rows'] = $this->data_model->getAll();
$this->load->view('home',$data);
}
}
module:
Code:
class Data_model extends CI_model {
function getAll() {
$rows = FALSE;
$this->db->select("idm, usa, level, name, href, sub, href_class, i_class, span_class, b_class");
$this->db->from('menu');
$q = $this->db->get();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row){
$data[] = $row;
}
return $data;
}
}
}
view: (of course after I can obtain to write the array menu on an .html static file or recall all the script to render more dinamik the menu)...
Code:
$menu = FALSE;
$tab = ' ';
$ul = 0;
$menu = "<ul class=\"nav nav-list\">\n";
foreach ($rows as $r):
$level = 9;
if ($level >= $r->level AND $r->usa ==1) {
$menu.= "$tab<li>\n";
$menu.= "$tab$tab<a >href\"";
if ($r->href_class == TRUE) {
$menu.= " class=\"$r->href_class\">\n";
} else {
$menu.= ">\n";
}
if ($r->i_class == TRUE) {
$menu.= "$tab$tab<i class=\"$r->i_class\"></i>\n";
}
if ($r->span_class == TRUE) {
$menu.= "$tab$tab<span class=\"menu-text\">$r->name</span>\n";
} else {
$menu.= $tab.$tab.$r->name."\n";
}
if ($r->b_class == TRUE) {
$menu.= "$tab$tab<b class=\"$r->b_class\"></b>\n";
}
$menu.= "$tab$tab</a>\n";
if ($r->sub == 1) {
++$ul;
$menu.= "$tab<ul class=\"submenu\">\n";
} elseif ($r->sub == 2) {
$c=1;
while($c<=$ul) {
$menu.= "$tab</li>\n";
$menu.= "$tab</ul>\n";
++$c;
}
$menu.= "$tab</li>\n";
$ul = 0;
} else {
$menu.= "$tab</li>\n";
}
}
endforeach;
$menu.= "</ul><!-- /.nav-list -->\n";
echo "<textarea cols=\"100\" rows=\"35\" read>$menu</textarea>\n";
thanks in advance
GioMBG