Easy Menu Formatting in Codeigniter
27 Aug 2011Formatting menus with appropriate CSS classes to define their state is messy and cumbersome at best, especially when not using a CMS, but something that is very much required to make websites usable. As a regular user of codeigniter it’s something I’ve been searching for a solution for (before bothering to roll my own) and fortunately I found a great solution: Steal the menu library from FuelCMS, full documentation here.
In this post I will give a simple example of generating the menu below using the FuelCMS Menu Class in Codeigniter.
Before (Plain HTML):
After (Generated):
FuelCMS is a CMS based on Codeigniter, it also contains many libraries which can be used with codeigniter independently of FuelCMS in general Codeigniter applications. One of which is the Menu Class. It does many things other than just basic menus like breadcrumb trails and collapsible menus and page titles so serves my purposes very well.
Example Usage
Add the setup code in the constructor of each controller where $this->data
is the data sent to the view. In the view $menu
contains the prepared html menu.