Codeigniter Dynamic Menu/MY_Controller question

Baldwonder

New Member
I generate a menu from a database table using a function, and I've placed this in an extended base controller class:\[code\]<?phpclass MY_Controller extends Controller { public function __construct() { parent::Controller(); } public function category_menu() { $this->load->model('category_model', 'category'); $categories = $this->category->get_categories(); $menu ="<ul class=\"menu_body\" id=\"nav_categories\">\n"; foreach($categories->result() as $row) { $menu .= "\t<li>" . anchor('listing/view' . $row->url, $row->name) . "</li>\n"; } $menu .= "</ul>\n"; return $menu; }}\[/code\]then naturally my controller looks like ~\[code\]<?phpclass Site extends MY_Controller { function __construct() { parent::__construct(); } function index() { $data['menu'] = $this->category_menu(); $this->load->view('view', $data); }}\[/code\]this does work, but it seems inefficient to have to do this for ~every~ page/view?Or is this just a limitation of CI/MVC and there's no other way of doing it.thanks for any insight
 
Back
Top