Tag: magento 2 admin menu

How to create admin menu in magento 2

My previous tutorial show you to create module in magento 2, Click here. Today I discuss about magento 2 admin menu.

Suppose module called “SR” and namesapce called “Weblog”.

In Magento 1, menu configuration are locate inside adminhtml.xml but in Magento 2 configuration is locate menu.xml file, location is

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
        <add id="SR_Weblog::blogpost" title="Weblog blogpost" module="SR_Weblog" sortOrder="300" parent="Magento_Backend::content_elements" action="weblog/blog" resource="SR_Weblog::blogpost"/>


Clear magento cache, and go to admin panel. You can change the menu, your new menu is appended with(Content -> Weblog blogpost).

Now you create a admin controller, file location is

namespace SR\Weblog\Controller\Adminhtml\Blog;

class Index extends \Magento\Backend\App\Action
     * Index action
     * @return void
    public function execute()
        die('Hello World!');

Create Router

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="weblog" frontName="weblog">
            <module name="SR_Weblog" before="Magento_Adminhtml" />

Clear magento cache

Now you browse Content ->Weblog blogpost, yes it’s working.