I am learning Magento2 and I have created adminhtml test module it's not working.

Can you please suggest me where i went wrong?

my code is:


'modules' =>
        array (
        'Magento_Test' => 1, 



namespace Magento\Test\Block\Adminhtml;
class Test extends use \Magento\Framework\View\Element\Template;
    public function _prepareLayout(){
        return parent::_prepareLayout();


 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
namespace Magento\Test\Controller\Adminhtml\Index;

class Index extends \Magento\Backend\App\Action
    public function execute() {


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Magento_Test" schema_version="">


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <router id="admin">
        <route id="test" frontName="test" >
            <module name="Magento_Test" />


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd">
            <resource id="Magento_Adminhtml::admin">
                <resource id="Magento_Test::test" title="Custom Module" sortOrder="40">
                    <resource id="Magento_Test::item" title="New Record" sortOrder="40" />
                <resource id="Magento_Adminhtml::stores">
                    <resource id="Magento_Adminhtml::stores_settings">
                        <resource id="Magento_Adminhtml::config">


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Backend/etc/menu.xsd">
        <add id="Magento_Test::test" title="test" module="Magento_Test" sortOrder="40" resource="Magento_Test::test"/>
        <add id="Magento_Test::item" title="New Record" module="Magento_Test" sortOrder="40" parent="Magento_Test::test" action="test/index/" resource="Magento_Test::item"/>


<?xml version="1.0" encoding="UTF-8"?>
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="formkey"/>
        <referenceContainer name="content">
            <block class="Magento\Test\Block\Adminhtml\Test" name="test_test" template="test/test.phtml">


<h1>Magento 2 Custom Module </h1>

url: http://localhost/magento-2/admin/test/index/index/

it's redirecting dashboard page while entering above url.

Can you please suggest me where i went wrong?


  • Is the module enable in store advance? Did you clear cache (rm -rf var/cache/* var/page_cache/* var/generation/*)? Commented Jul 21, 2015 at 14:03
  • @R.S, Yes I have cleared. Still not executing my module. Is it right my code? or something went wrong? Commented Jul 21, 2015 at 14:13
  • Side note: Please don't use "Magento_Test" as a module name in practice. "Magento_*" is reserved for use by Magento. Use your own vendor name (I use "AlanKent" for my own play projects.)
    – Alan Kent
    Commented Jul 22, 2015 at 4:53
  • Not an answer, but have you looked at github.com/magento/magento2-samples? Might be something useful there to learn from.
    – Alan Kent
    Commented Jul 22, 2015 at 4:56
  • 1
    I copied your files to my tree. I deleted var/*. I got an error talking about the module.xml file (in developer mode) - I changed "schema_version" to "setup_version" and then ran "magento setup:upgrade". I went to the Admin page and selected Store / Configuration / Advanced / Advanced and expanded "disable module output". The Magento_Test module was visible. So its being loaded. I played a bit longer, but had other things to get done. But I certainly came away with ideas for improvements that would make debugging easier!!
    – Alan Kent
    Commented Jul 23, 2015 at 0:50

2 Answers 2


routers.xml should be routes.xml. See this file as example

  • Still not executing my module. Is it right my code? or something went wrong? Commented Jul 21, 2015 at 14:17
  • Clear the cache after the filename change. If that doesn't work I have no other ideas.
    – Marius
    Commented Jul 21, 2015 at 14:23

I've created menu.xml in /view/adminhtml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> <menu> <add id="Vendor_MyModule::mymodule_index" title="My Module" module="Vendor_MyModule" sortOrder="0" parent="Magento_Backend::content_elements" action="mymodule/index" resource="Vendor_MyModule::index"/> </menu> </config> I copied this from cms module and updated it with my module information. I can see the item under Content -> Elements in admin menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.