简体   繁体   中英

Joomla 3 component: create Menu/menu items during installation

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

You can create the installer script file, and write there some code which will run eg 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. Eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM