1

On Magento 2.4.6 I am trying to create an option from the admin panel to navigate to a newly created page.

enter image description here

When trying to do this I get an error:

Invalid security or form key. Please refresh the page.

enter image description here

Could you please help me what I am doing wrong?

My code:

app\code\Dev\Controller\Adminhtml\Controller\Index.php:

namespace Dev\Controller\Adminhtml\Controller;


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

class Index extends Action
{
    protected $resultPageFactory;

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

    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__('Dev Module Page'));
        return $resultPage;
    }
}

app\code\Dev\RestApi\etc\adminhtml\menu.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Dev_RestApi::dev_module" title="Dev Module" module="Dev_RestApi" sortOrder="10" parent="Magento_Backend::content" resource="Dev_RestApi::dev_module"/>
        <add id="Dev_RestApi::dev_module_PriceInfo_Module" title="PriceInfo_Module" module="Dev_RestApi" sortOrder="10" parent="Dev_RestApi::dev_module" action="dev/controller/action" resource="Dev_RestApi::dev_module_PriceInfo_Module"/>
    </menu>
</config>

app\code\Dev\RestApi\etc\adminhtml\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="dev" frontName="dev">
            <module name="Dev_RestApi" />
        </route>
    </router>
</config>

app\code\Dev\RestApi\etc\acl.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Dev_RestApi::dev" title="Dev Module" sortOrder="10">
                    <resource id="Dev_RestApi::dev_index" title="Dev Index" sortOrder="10" />
                </resource>
            </resource>
        </resources>
    </acl>
</config>

2 Answers 2

0

Incorrect Your Controller Path

app\code\Dev\Controller\Adminhtml\Controller\Index.php

replace with

app\code\Dev\RestApi\Controller\Adminhtml\Controller\Index.php

and also change the namespace of your Controller

1
  • Thank you very much! This solution helped.
    – User
    Commented Sep 5, 2023 at 13:45
2
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Dev_RestApi::dev_module" title="Dev Module" module="Dev_RestApi" sortOrder="10" parent="Magento_Backend::content" resource="Dev_RestApi::dev_module"/>
        <add id="Dev_RestApi::dev_module_PriceInfo_Module" title="PriceInfo_Module" module="Dev_RestApi" sortOrder="10" parent="Dev_RestApi::dev_module" action="dev/controller/index" resource="Dev_RestApi::dev_module_PriceInfo_Module"/>
    </menu>
</config>

try this app\code\Dev\RestApi\etc\adminhtml\menu.xml:

The proplem is action="dev/controller/action" this needs to be action="dev/controller/index"

1
  • Thanks for the reply! It looks like I did make a mistake here, but it didn't solve the problem...
    – User
    Commented Sep 5, 2023 at 13:11

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.