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

app/code/SR/Weblog/etc/adminhtml/menu.xml
<?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="SR_Weblog::blogpost" title="Weblog blogpost" module="SR_Weblog" sortOrder="300" parent="Magento_Backend::content_elements" action="weblog/blog" resource="SR_Weblog::blogpost"/>
    </menu>
</config>

Done!

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

app/code/SR/Weblog/Controller/Adminhtml/Blog/Index.php
<?php
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
app/code/SR/Weblog/etc/adminhtml/routes.xml

<?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" />
        </route>
    </router>
</config>

Clear magento cache

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

11 thoughts on “How to create admin menu in magento 2

      1. hi i want to know that how can i rewrite the app/code/core/mage/checkout/onepage/abstract.php. i rewrite app/code/core/mage/checkout/onepage/shipping.php and its working properly… but abstract not working…. and u may see how i rewrite shipping.php file

        LikiextCheckout_Checkout_Block_Onepage_Shipping

        thanks regards

      2. “app/code/core/mage/checkout/onepage/abstract.php” put new location “app/code/local/mage/checkout/onepage/abstract.php”

  1. Thanks for the tutorial, I get the navigation option per your tutorial, but am at a loss as to where the router is going to load the content to add a new blog post :/
    Could you zip up your working copy and attach it to the blog or link to a git repo with the working example?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s