Database driven menu? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Database driven menu? (/showthread.php?tid=1239) |
Database driven menu? - sandeep - 02-21-2015 How to create a database driven Menu and autoload this on every pages/Controllers of project? RE: Database driven menu? - RobertSF - 02-22-2015 I suppose your menu will consist of menu text and a URL to go to when you click on the menu text. You will also want several menus, so I think your database table will look something like this. Code: Table: menus In your model file, you will have a function for retrieving all the menu entries for a particular menu name. Something like this. PHP Code: public function get_menu($menu_name) In your controller file, perhaps in the constructor, you would have something like this. PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); When you call your view file, you'll have to include $menu in the $data array. And in your view file, you'll display the menu using something like this. You could put this code in a partial view file, like sidebar_view.php, something that you load with every view. PHP Code: <div id="sidebar"> I've chosen to use a definition list to display the menu. You could use any kind of list, or no list at all, but I've read that, semantically, definition list is the best for menus. You could enhance this with a field for disabled = true/false, so you could disable specific entries. You could also add a field for permissions that determined which kind of user could access the menu. I hope this is what you were looking for! |