Вопрос

I have been struggling with this error all day, I have tried all the solutions on Internet, but it keeps showing 404 Error when I click the link on my custom menu.

Here is my code

/app/code/Vendor/Module/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="Vendor_Module::menu" title="Sift Science" module="Vendor_Module" sortOrder="51" resource="Vendor_Module::menu"/>
        <add id="Vendor_Module::menu_item" title="Configuration" module="Vendor_Module" sortOrder="10" parent="Vendor_Module::menu" action="SiftMenu/ConfigMenu/" resource="Vendor_Module::menu_item"/>
    </menu>
</config>

Controller /app/code/Vendor/Module/Controller/Adminhtml/ConfigMenu/SiftSetup.php

<?php

namespace Vendor\Module\Controller\adminhtml\configmenu;



use \Magento\Backend\App\Action;
use \Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use \Magento\Framework\Json\Helper\Data;

class SiftSetup extends Action
{
    protected $resultPageFactory;
    protected $jsonHelper;

    public function __construct(Context $context, PageFactory $pageFactory, Data $jsonHelper )
    {
        $this->resultPageFactory = $pageFactory;
        $this->jsonHelper = $jsonHelper;
        parent::__construct($context);
    }

    public function execute()
    {


        die ("test module");


    }
}

routes.xml /app/code/Vendor/Module/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="standard">
        <route id="SiftMenu" frontName="SiftMenu">
            <module name="Vendor_Module" />
        </route>

    </router>
</config>
Это было полезно?

Решение

You first should change the namespace for controller's action

namespace Vendor\Module\Controller\Adminhtml\ConfigMenu; //Capital for first letter

You should change your action in the menu.xml:

<add id="Vendor_Module::menu_item" 
    title="Configuration" module="Vendor_Module" sortOrder="10" 
    parent="Vendor_Module::menu" 
    action="siftMenu/configMenu/siftSetup"    #full controller-action pattern
    resource="Vendor_Module::menu_item"/> 

You also need to change the routes.xml in etc/adminhtml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin"> <!-- admin -->
        <route id="SiftMenu" frontName="SiftMenu">
           <module name="Vendor_Module"/>
         </route>
     </router>
</config>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top