Read More
Read More
Menu Close

    Create menu item in Joomla and rebuild Automatically


    If we want to create menu item from your custom component in Joomla as there is no documentation or method in Joomla API, so we have to create it using the database. But when we do it directly we are not able to make complete entries for it as we can’t populate values for lft and rgt fields by using query and logic, and these values are also very important in Joomla for Ordering.
    The process to create menu item from a custom component is to first create a menu type entry and also a corresponding entry in the Assets then we can create the menu items as per Joomla Standards.


    To Create a proper menu item you need to follow the steps:

    **Please note the methods called below are not in any class in this case if you add these methods to a class please use proper instance to call them

    In your code add

    Method’s Defination


    When creating the menu item in Joomla using with this all entries will be filled as per Joomla.

    The corresponding entry for the menutype will be created in the #__assets with the lft and rgt, also you do not need to worry about the lft and rgt value in the #__menuitem as they will be filled when the JTable store() method is called, so you will not require to rebuild the menu items.

    Start your headless eCommerce
    Read More

    If you find this helpful please like and Share, so others can also find this solution.

    If you have any query please feel free to comment below.


    Supported Framework Version - Joomla 3.X

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


  • dim
    Hello, thank you for your code.
    Could you please describe how to add a submenu for an existing menu ?
    Thank you !
    • Pratyush Painuly (Moderator)
      To create a submenu, call createMenuitem() with the properties array containing the index “parent_id” which is the parent menu item in the menu tree, also you need to set index “level” the relative level in the tree.
      You can check Table Menu for reference as $menu in the createMenuitem() is instance of that table.

      Hope this helps

  • Mairon
    how do I import the files needed to effectively perform the creation of a menu item in joomla, I’m having trouble in that part, thanks!
    • Pratyush Painuly (Moderator)
      There are no such files required that you need to import for this, if you are trying to create menu-items for an extension at the time of installation, then you can add it to your script file and perform this action by implementing method like “postflight” so the menu-items are created only after the installation.

      You can take help from for script file of extension:

      If this is not the case please explain so we can guide you in a better way.

      • Mairon
        I’m trying to create just a menu item, in the existing menu in joomla using a php form, it works as follows, there is a form in php for it to automatically create a menu item every time a product is inserted into the site by any seller.
        • Pratyush Painuly (Moderator)
          For this you will need to implement only createMenuitem() in a PHP file(helper will be a good option here), then on successful product creation you can call method with product data as:

          $classObj->createMenuitem(MENU_TYPE, PRODUCT_NAME,
          'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=PRODUCT_ID',array( 'component_id' => (int)$virtuemart_component_id));

          You will be able to create the menu-item for product using this but need to supply all the required data like this.
          Hope this helps, if you like this blog please like and share.

          • Mairon Piber
            Hello, I still can not create a menu item automatically, every time I make the call to the file containing the createItemmenu function, the joomla returns me an error, is there a specific location to save the php file with the function or something that I need to go in the header? I tried in many different ways and still did not get results, I also tried to put the function in the same file as I call it and still did not succeed.
            I’m using joomla 3.9.8
          • Pratyush Painuly (Moderator)
            Hello, I need to know more details of this process so I can understand your issue in a better way.
            The information on the error you received and how are you calling the function is the important part without which I will not be able you provide you much help.
            Please send your query along with these details on [email protected] or raise a ticket on our support, sharing these details in public comments is not advised.
  • Back to Top

    Table of Content