Monday, March 12, 2012

How to ADD menu in Joomla Admin Panel



I was been searching for how to add menu in joomla admin panel, and finally found this most useful method:

A) If you are developing a Joomla! component and wants to have menu & sub menu automatically created with the installation of component then follow below:

1. Please add menu and sub menu details in the back end top bar using below code in the componentname.xml file (Please add similar code with your own details in the administration block of the xml file):





Main Menu Name/Component Name

Menu Item 1
Menu Item 2
Menu Item 3
Menu Item 4
Menu Item 5


B) If you are developing a Joomla! component and have not completed the development yet then create menu & sub menus manually using below method – this method is also useful if your component does not have quick links and you want to add them:

Please open your database using phpMyAdmin or any other easy database management tool and then open jos_components table. Please copy the below sql query and change it to meet with your details and run it, it will add menu & sub menus for your component:

INSERT INTO `jos_components` (`id`, `name`, `link`, `menuid`, `parent`,
`admin_menu_link`, `admin_menu_alt`, `option`, `ordering`, `admin_menu_img`,
`iscore`, `params`, `enabled`) VALUES

(1, 'Main Menu Name/Component Name', 'option=com_componentname', 0, 0,
'option= com_componentname', 'Main Menu Name/Component Name',
'com_componentname', 0, 'path to icon file', 0, '', 1),
(2, 'Menu Item 1', '', 0, 1, 'option= com_componentname&view=menuitem1',
'Menu Item 1', 'com_componentname', 2, 'path to icon file', 0, '', 1),
(3, 'Menu Item 2', '', 0, 1, 'option= com_componentname&view=menuitem2',
'Menu Item 2', 'com_componentname', 1, 'path to icon file', 0, '', 1),
(4, 'Menu Item 3', '', 0, 1, 'option= com_componentname&view=menuitem3',
'Menu Item 3', 'com_componentname', 3, 'path to icon file', 0, '', 1),
(5, 'Menu Item 4', '', 0, 1, 'option= com_componentname&view=menuitem4',
'Menu Item 4', 'com_componentname', 4, 'path to icon file', 0, '', 1),
(6, 'Menu Item 5', '', 0, 1, 'option= com_componentname&view=menuitem5',
'Menu Item 5', 'com_componentname', 5, 'path to icon file', 0, '', 1);


NOTE:


1) Entry in the XML file ensures this to be taken care while installing the Joomla Component and then it adds the menu and sub menu at the same time automatically to Joomla! administration menu by making entry into __components DB table
2) Manual entry in the db is required to make it possible as if installation was not done using XML file or you are developing a component but after completion of such component, please make sure to include this in the XML file so that user can do the complete automated installation easily

3) Please note, here path to icon file could be like as below:

components/com_componentname/assets/icons/icon-name.gif

Here, it is always useful to put all the icons files in the assets folder of the component which is used to store all the additional files to provide them as needed.

4) Sub menus will be linked as if you enter proper parent Id for them in the above DB table.
5) Please make sure to update corresponding names with your component details.
Of course, for any query or further assistance – just write your message and I will be happy to respond ASAP




No comments: