Reputation: 681
Is there a build in way to create a menu/menu items (FRONT-END!) during installation of a component?
This is not about the .xml file in the tmpl folder!. What I'm after is to have a Joomla 3 menu (plus menu items to my views) ready to use after I installed my component.
I know I could write some SQL and insert directly into the Menu / Menu_item tables. But that doesn't feel right. With all the setup option available it seem strange not to have the option to crate a front-end menu.
What I mean with option is: in the manifest file I can use within the administrator section to create my back-end menu, which is stored in the same db table (different type). But I can not do the same for the front-end?
If I must use the SQL approach, when/where/how? Or do I have to write/install a plugin to achieve this?
Regards
Andreas
Upvotes: 0
Views: 576
Reputation: 340
You can create the installer script file, and write there some code which will run e.g. after your component is installed in: administrator/components/com_xyz/script.php
class com_xyzInstallerScript {
function postflight($type, $parent) {
//...
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert($db->quoteName('#__menu'))
->columns( ... )
->values( ... );
//...
}
}
You can search in the joomla installation .sql scripts for more ideas related with the menu module. E.g. in installation the mainmenu is by default populated.
I guess it is more complicated when it comes to front-end menu and there is no current support in the component's installation file (at least i dont know any). In the administrator, the menu item will appear in an existed menu - the Components menu -, and the harthon template is usually used, wheres in the front-end the menu must be created from scratch.
Upvotes: 1