Magento 2 – What Should the Action Attribute in menu.xml Be?

adminhtmlmagento-2.1magento2menu

In the file menu.xml located in MyNamespace\Mymodule\etc\adminhtml\menu.xml, I understand that this file allows me to add new items to the navigation menu in admin panel.

In the <add> tags, there is an action attribute that contains values that look like something/somethingelse. For eg:

<add id="MyNamespace_MyModule::mymodule_testing" title="Some title" module="MyNamespace_MyModule" sortOrder="10" action="Part_A/Part_B" />

What should be entered in the Part_A and Part_B of the action attribute? I doubt they are arbitrary. What do they refer to and what do they stand for? What effects would it have if I put in a wrong thing into this attribute?

Best Answer

Let's say you have the following:

In your etc/adminhtml/routes.xml you declare the following route name:

<route id="hello" frontName="hello">
    <module name="Vendor_Module" />
</route>

Then under Controller/Adminhtml you have a folder called World

And finally in this World folder you have an action class called Grid.php

Then the action attribute to access this controller action class should be hello/world/grid

Related Topic