0

I have followed many tutorials but im still getting a 404 error when trying to access with a custom menu item in my module.

This is what i have, : registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Digital_Custom',
__DIR__
);

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="Digital_Custom::regenerate"
             title="Digital Custom"
             module="Digital_Custom"
             sortOrder="9999"
             action="importer/packadgeable/regenerate"
             resource="Magento_Backend::content" />

    </menu>
</config>

Here the new menu item is visible, but when click im getting 404

My controller Structure:

Digital - Custom - Controller - Adminhtml - Packadgeable - Regenerate.php This is my controller code Regenerate.php

<?php
namespace Digital\Custom\Controller\Adminhtml\Custom;

class Regenerate extends \Magento\Backend\App\Action
{
    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $_resultPageFactory;

    /**
     * @param \Magento\Backend\App\Action\Context        $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) 
    {
        parent::__construct($context);
        $this->_resultPageFactory = $resultPageFactory;
    }

    /**
     * Grid List page.
     *
     * @return \Magento\Backend\Model\View\Result\Page
     */
    public function execute()
    {
        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->_resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__('Grid List'));

        return $resultPage;
    }

    protected function _isAllowed() {
        return true;
        }
}

My route etc/adminhtml/routes.xml

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

1 Answer 1

1

I'd say the URL isn't matching. Instead of:

action="importer/packadgeable/regenerate"

you should try:

action="regenerate/packadgeable/regenerate"

or change the route id and frontName to importer.

2
  • Yes, that was the mistake, got it few hours ago, thank you! Commented Apr 25, 2018 at 20:07
  • This helped me more. Thanks :)
    – Ask Xah
    Commented Sep 16, 2019 at 13:38

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.