Magento 2 Create Admin Menu

Follow the below steps to create admin manu in Magento 2.

Step 1: Create menu.xml
Step 2: Add menu item
Step 3: Flush Magento cache

Step 1: Create menu.xml

Create admin menu file called: menu.xml file

app/code/PHPCodez/First/etc/adminhtml/menu.xml and insert the following content.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
 <menu>
 </menu>
</config>

Step 2: Add menu item

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
 <menu>
 <add id="PHPCodez_First::first" title="PHPCodez" module="PHPCodez_First" sortOrder="51" resource="PHPCodez_First::first"/>
 <add id="PHPCodez_First::post" title="Manage Posts" module="PHPCodez_First" sortOrder="10" action="PHPCodez_First/post" resource="PHPCodez_First::post" parent="PHPCodez_First::first"/>
 <add id="PHPCodez_First::first_configuration" title="Configuration" module="PHPCodez_First" sortOrder="99" parent="PHPCodez_First::first" action="adminhtml/system_config/edit/section/first" resource="PHPCodez_First::first_configuration"/>
 </menu>
</config>

The id attribute is the identifier for this note. It’s a unique string and should follow the format: {Vendor_ModuleName}::{menu_description}.

The title attribute is the text which will be shown on the menu bar.
The module attribute is defined the module which this menu is belong to.

The sortOrder attribute is defined the position of the menu. Lower value will display on top of menu.

The parent attribute is an Id of other menu node. It will tell Magento that this menu is a child of another menu. In this example, we have parent=”Mageplaza_HelloWorld::helloworld”, so we – know this menu “Manage Posts” is a child of “Hello World” menu and it will show inside of Hello World menu.

The action attribute will define the url of the page which this menu link to. As we talk above, the url will be followed this format {router_name}{controller_folder}{action_name}. – In this example, this menu will link to the module HelloWorld, controller Post and action Index

The resource attribute is used to defined the ACL rule which the admin user must have in order to see and access this menu. We will find more detail about ACL in other topic.

Step 3: Flush Magento cache

Run the following command line:

php bin/magento cache:clean

Now go to Magento 2 Admin and see result

Leave a Reply

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