Adding Menu Items

Modules are responsible for adding menu items to the administration area, this is achieved by overriding the method build_admin_menu() in the module information file mymodule_module.php.

This method takes a parameter which is used to add to the menu collection:

public function build_admin_menu($menu) { }

The first parameter in this method $menu is an object that represents the top level of the menu. You can add() new menu items to this top level which returns another object which represents the sub menu items. From here you can add_child() menu items to the sub menu.

Adding top level and sub menu items

Assuming you have already set up a basic module, you should update or add the module information file with this content:


class Blog_Module extends Core_Module_Base

	protected function set_module_info()
		return new Core_Module_Detail(
			"Blog Module",

	public function build_admin_menu($menu)
		$top = $menu->add('blog', 'Blog', 'blog/posts')->icon('microphone');
		$top->add_child('posts', 'Posts', 'blog/posts', 100);
		$top->add_child('categories', 'Categories', 'blog/categories', 100);

The code above creates a top level menu item called Blog accompanied by two sub menu items, Posts and Categories.