4

I add a custom module , it has a backend manager,when i add a menu in backend,302 errors menu.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Magezoom_Adminmenu::adminmenu" module="Magezoom_Adminmenu" title="Magezoom" translate="title"  sortOrder="999"  resource="Magezoom_Adminmenu::adminmenu"/>
        <add id="Magezoom_Navigation::setting" title="Design" translate="title" module="Magezoom_Navigation" sortOrder="20" parent="Magezoom_Adminmenu::adminmenu" resource="Magezoom_Adminmenu::adminmenu"/>
        <add id="Magezoom_Navigation::navigation" title="Navigation" translate="title" module="Magezoom_Navigation" sortOrder="20" parent="Magezoom_Navigation::setting" resource="Magezoom_Adminmenu::adminmenu"  action="adminhtml/navigation" />
    </menu>
</config>

routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="navigation" frontName="navigation">
            <module name="Magezoom_Navigation" />
        </route>
    </router>
</config>

controller Index.php

<?php
namespace Magezoom\Navigation\Controller\Adminhtml\Index;

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

    /**
     * Constructor
     *
     * @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;
    }

    /**
     * Load the page defined in view/adminhtml/layout/exampleadminnewpage_helloworld_index.xml
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
         return  $resultPage = $this->resultPageFactory->create();
    }
  }
?>

debug.log

about 10 times

main.DEBUG: Request validation failed for action "Magento\Framework\App\Action\Forward\Interceptor" [] []

url become this:

http://magento-dev.com/admin/admin/navigation/index/key/a94a1b0e9c7dfd64a3f6cf422d5381deac7111115166375a4107dbd10c71c773/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/adminhtml/dashboard
4
  • In that case You should have more errors in your php logs. Maybe in /var/log/apache2/error.log
    – BartZalas
    Commented Jun 2, 2019 at 22:40
  • There is no error in apache error log file
    – XieWilliam
    Commented Jun 2, 2019 at 22:46
  • What if you un-comment the line ini_set in app/bootstrap.php
    – BartZalas
    Commented Jun 2, 2019 at 22:50
  • It's already un-commented
    – XieWilliam
    Commented Jun 2, 2019 at 23:01

6 Answers 6

6

First things first, controller action should extend Magento\Framework\App\Action\Action class and implement Magento\Framework\App\Action\Http<method>ActionInterface where is one of HTTP Request methods. Magento uses Magento\Framework\App\Request\CompositeValidator to validate requests, on validation error you get Request validation failed for action ...

To address your issue you need to pinpoint validator that failed. In my case (with was a POST controller retrieving a data from another service) my request lacked a param isAjax = true, when I added this param to the URL (like so: http://127.0.0.1/<my_route>?isAjax=true) it solved my problem. In your case, it might be another validator so the solution is not universal.

Validators that take part in validating POST requests are:

Magento\Framework\App\Request\CsrfValidator and Magento\Framework\App\Request\HttpMethodValidator

Summarising:

class <MethodName> extends Magento\Framework\App\Action\Action implements Magento\Framework\App\Action\HttpPostActionInterface
{
    public function execute(): \Magento\Framework\Controller\ResultInterface|ResponseInterface
    {
        return $this->resultFactory->create();
    }
}

and the url: http://127.0.0.1/<my_route>?isAjax=true request method POST

1
  • How to pinpoint which validator failing
    – Pawankumar
    Commented Sep 8, 2020 at 13:49
1

Issue may also happen if admin router front name is used in getUrl instead of router id as security parameter 'key' is generated based on the route path. Magento front controller matches corresponding router and action and then it uses router ID and controller action name. It newer uses router front name. Front name is used in URLs in FE just to make them more readable, shorter, laconic, etc.

0

You can try like this:

<?php

namespace Magezoom\Navigation\Controller\Adminhtml\Index;

use Magento\Framework\Controller\ResultFactory;

class Index extends \Magento\Backend\App\Action
{          
    public function execute()
    {
         return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
    }
}  

And in your menu, change the value of resource

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Magezoom_Adminmenu::adminmenu" module="Magezoom_Adminmenu" title="Magezoom" translate="title"  sortOrder="999"  resource="Magezoom_Adminmenu::adminmenu"/>
        <add id="Magezoom_Navigation::setting" title="Design" translate="title" module="Magezoom_Navigation" sortOrder="20" parent="Magezoom_Adminmenu::adminmenu" resource="Magezoom_Navigation::setting"/>
        <add id="Magezoom_Navigation::navigation" title="Navigation" translate="title" module="Magezoom_Navigation" sortOrder="20" parent="Magezoom_Navigation::setting" resource="Magezoom_Navigation::navigation"  action="adminhtml/navigation" />
    </menu>
</config>  

If action doesn't work correctly, you can try like : action="navigation"

12
  • Does it need clean cache?Which cache should be cleaned?
    – XieWilliam
    Commented Jun 3, 2019 at 13:08
  • have you tried my answer? after applying changes above, run upgrade, di:compile then redeploy static contents. it should work
    – fmsthird
    Commented Jun 3, 2019 at 14:15
  • not working after un upgrade, di:compile and redeploy static contents
    – XieWilliam
    Commented Jun 3, 2019 at 20:18
  • the url changes, is that after you apply the changes in the code?
    – fmsthird
    Commented Jun 3, 2019 at 20:43
  • 4
    I solved this problem finaly, controller namespace was wrong
    – XieWilliam
    Commented Jun 4, 2019 at 2:20
0

In my case, it is the form_key. I've added form key input field explicitly in and it solved the issue.

0

Check for typos in the controller's class name, or the filename etc. You might have a lowercase 's' when you need a capital 'S', for example.

-1

I think the problem is from data you had input. If there's no other logs written by Magento system, I think the problem is from your server system. You need to go to server error log to detect it. In this case, I think it's the size limit of variable (upload files size) in your PHP config.

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.