• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

how to generate menu from database simple code new in codeigniter

you need to create a database table that contains at least menu_label, menu_link

then you need to create a model method to retrieve records from this table

$query = $this->db->get('yourTableName');
return $query->result();

run this in your controller and pass it to the view
in controller
// load your model

$data['menu_items'] = $this->your_model->get_menu();
$this->load->view('view_file', $data);

and in view file
foreach($menu_items as $menu_item)
     echo '<li>' . $menu_item->menu_label . '</li>';

then style your li list as you need, add <a > tag with menu_link

You can create a library that will generate a menu or create a model that will return menu items.
But there is no universal code, since each has its own application structure.
if the menu is generated from a single table, use Krystian's code.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.