Menu Model
Menus are managed at Layout > Menu Manager. This model, however, allows you to programmatically modify menus, clear the menu cache, etc.
Menus are cached to reduce the number of database queries per page load. Menu data is stored in cache files automatically.
Initialization
$this->load->model('menu_manager/menu_model');
// methods: $this->menu_model->new_menu(), etc.
Method Reference
void clear_cache ()
Clear the menu cache files. This should be called whenever a menu or link is modified.
int new_menu (string $name)
Create a new menu.
int add_link (int $menu_id , int $parent_link , string $type , int $link_id , string $text [, string $special_type = FALSE [, string $external_url = FALSE [, array $privileges = array()]]])
Add a link to a menu. "Special" links have some magic in that they may generate multiple menu items, or dynamically modify their menu items, depending on other factors. The following are special links:
- home - Always links to the frontpage
- control_panel - Always links to the control panel
- my_account - Will generate links differently depending on logged in/out status. May generate 2nd tier links if you are logged in, for account management.
- store - Link to the store and store collections in the 2nd tier.
- search - Links to your search page.
- subscriptions - Links to your subscription listings page.
- cart - Links to your cart.
int update_link (int $menu_link_id , string $text [, array $privileges = array() [, string $class = FALSE]])
Update an existing link.
void remove_link ()
Remove an existing link.
array get_menu ($menu_id)
Retrieve a single menu referenced by its ID, in the same format as get_menus().
void delete_menu ($menu_id)
Delete a menu and all of its links.
array get_menu_by_name ($menu_name)
Retrieve a single menu referenced by its name, in the same format as get_menus().
array get_menus ( [array $filters = array()])
Retrieve a menu or menus based on optional filters.
Possible Filters:
- int id
- int name
Each menu has the following data:
- id
- name
array get_link (int $id)
Return a single link, in the format of get_links()
array get_links ( [array $filters = array() [, boolean $no_cache = FALSE ]])
Return one or more links based on optional filters.
Possible Filters:
- int id
- int name
- int menu - Menu ID
- int parent - Parent link ID
Each returned link has the following data:
- id
- menu_id - The menu it belongs to
- children - How many children does it have?
- parent_menu_link_id - Does it have a parent link in the menu?
- text - The menu text
- type - The type of link
- class - Any class(es) that should be attributed to the link's <li> element in the generated menu.
- link_id - The link ID generated by the link model
- special_type - If it's a special type, what kind?
- external_url - If it's an external URL, what's the URL?
- privileges - An array of member groups who can see the link
- order - The order of the link within its menu/siblings
- link_url_path - The local link path, if available