1

I'm having some issues setting up admin routing.

My menu.xml file is as follows, note the custom route /manufacturer/grid.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
    <add id="Amrita_Manufacturer::manufacturers_second_level"
         title="Manufacturers"
         module="Amrita_Manufacturer"
         sortOrder="9999"
         resource="Amrita_Manufacturer::manufacturer"
         parent="Magento_Catalog::inventory"
         action="/manufacturer/grid"
    />
</menu>

routes.xml looks like this

<?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="manufacturer" frontName="manufacturer">
            <module name="Amrita_Manufacturer" />
        </route>
    </router>
</config>

and my Index.php file is located in the following directory Amrita\Manufacturer\Controller\Adminhtml\Grid

Am i doing something wrong, I've tried a number of different suggestions and the menu link just redirects to the dashboard page?

3

having some issues setting up admin routing.

As per the Magento routing, The router is looking for /manufacturer/grid/Index not manufacturer/grid. This means admin Controller should be placed root\app\code\Amrita\Manufacturer\Controller\Adminhtml\Grid\Index.php

Please refer the code added for quick reference.

\app\code\Amrita\Manufacturer\etc\adminhtml\routes.xml

<router id="admin">
    <route id="manufacturer" frontName="manufacturer">
        <module name="Amrita_Manufacturer" before="Magento_Backend" />
    </route>
</router>

\app\code\Amrita\Manufacturer\etc\adminhtml\menu.xml

<menu>
    <add id="Amrita_Manufacturer::amrita_manufacturergrid" title="Manufacturers" module="Amrita_Manufacturer" parent="" sortOrder="20" dependsOnModule="Amrita_Manufacturer" action="manufacturer/grid" resource="Amrita_Manufacturer::amrita_manufacturergrid"/>
</menu>

\app\code\Amrita\Manufacturer\Controller\Adminhtml\Grid\Index.php

namespace Amrita\Manufacturer\Controller\Adminhtml\Grid;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class Index extends \Magento\Backend\App\Action
{

    /**
 * @var PageFactory
 */
protected $resultPageFactory;

/**
 * @param Context $context
 * @param PageFactory $resultPageFactory
 */
public function __construct(
    Context $context,
    PageFactory $resultPageFactory
) {
    parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
    /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
    $resultPage = $this->resultPageFactory->create();
        return $resultPage;
    }
}

\app\code\Amrita\Manufacturer\view\adminhtml\layout\manufacturer_grid_index.xml

 <body>     
    <referenceContainer name="content">         
        <block class="Amrita\Manufacturer\Block\Adminhtml\Manufacturer\Grid" name="manufacturer_grid" template="manufacturer\grid.phtml">
        </block>
    </referenceContainer>       
</body>

\app\code\Amrita\Manufacturer\Block\Adminhtml\Manufacturer\Grid.php

namespace Amrita\Manufacturer\Block\Adminhtml\Manufacturer;
class Grid extends \Magento\Backend\Block\Template
{

}

Make the template as well as, Hope this helps.

  • Hi, this has resolved the issue, i think there was a problem in the index.php file where i specified the namespace. Thanks, Sophie – Sophie Baxter May 25 '16 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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