1

I have succesfully added a new admin menu. But the problem is whenever i clicked the admin menu button, I got Invalid security or form key. Please refresh the page.

Here're some of my codes.

This is my menu.xml

     <add id="Testing_Basic::menu_item" title="Manage Items" module="Testing_Basic" sortOrder="10" parent="Testing_Basic::menu" action="Webpage/Create/Index" resource="Testing_Basic::menu_item"/>

And this is my directories looks like.

enter image description here

enter image description here

This is my

Controller/Adminhtml/Webpage/Index.php

<?php
/**
* Webkul Grid Controller
*
* @category    Webkul
* @package     Webkul_Grid
* @author      Webkul Software Private Limited
*
*/
namespace Testing\Basic\Controller\Adminhtml\Webpage;

class Index 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->setActiveMenu('Testing_Basic::grid_list');
    $resultPage->getConfig()->getTitle()->prepend(__('Grid List'));

    return $resultPage;
}

/**
 * Check Grid List Permission.
 *
 * @return bool
 */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Testing_Basic::grid_list');
    }
  }

And this is my routes.xml

    <?xml version="1.0"?>
    <!--
    /**
    * Webkul_Grid route xml
    *
    * @category    Webkul
    * @package     Webkul_Grid
    * @author      Webkul Software Private Limited
    *
    */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
     <router id="admin">
       <route id="create" frontName="create">
       <module name="Testing_Basic" />
       </route>
       </router>
    </config>
  • Answer is here magento.stackexchange.com/questions/301930/… – Msquare Feb 19 at 3:28
  • Please add your index controller and routes.xml file code also. – Kishor Thummar Feb 19 at 4:35
  • @Msquare thanks. I tried following your tutorial but I stuck in blank page. There's no side menu whenever I clicked the button. – Daniel_C Feb 19 at 18:47
  • @KishorThummar added my routes and index controller – Daniel_C Feb 19 at 18:56
  • Show your error here – Msquare Feb 20 at 3:24
4

add code in menu.xml

 <add 
    id="Testing_Basic::item" 
    title="Manage Items" 
    module="Testing_Basic" 
    sortOrder="10" 
    parent="Testing_Basic::menu" 
    action="create/webpage/index" 
    resource="Testing_Basic::item"
    />

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="admin">
        <route id="create" frontName="create">
            <module name="Testing_Basic" />
        </route>
    </router>
</config>

and controler file path like

/Controller/Adminhtml/Webpage/Index.php

<?php
namespace Testing\Basic\Controller\Adminhtml\Webpage;

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

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

    /**
     * Index action
     *
     * @return \Magento\Backend\Model\View\Result\Page
     */
    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->setActiveMenu('Testing_Basic::item');
        $resultPage->addBreadcrumb(__('Grid List'), __('Grid List'));
        $resultPage->addBreadcrumb(__('Manage Grid'), __('Manage Grid'));
        $resultPage->getConfig()->getTitle()->prepend(__('Grid List'));

        return $resultPage;
    }
}

hope this help you. :)

| improve this answer | |
  • Thanks its finally not showing the error. Just realize that I put "s" in my controller. But I must be missing something because the button is redirecting to blank page now. – Daniel_C Feb 19 at 18:12
  • added my index controller code.. – Daniel_C Feb 19 at 18:33
  • thanks. It's finally showing up. Thanks for the help – Daniel_C Feb 20 at 16:34
0

It might help someone, Today, I faced the same issue Magento ver. 2.3.5 none of the above methods works for me: Then I checked the module controller and found this code :

 /**
     * {@inheritdoc}
     */
    public function _isAllowed()
    {
        return $this->_authorization->isAllowed('Mymodule_Test::Test');
    }

Solution: Update Users Role from admin and it will resolve the issue.

| improve this answer | |
0

I had this issue in Magento 2.4.0. The reason was because the module folder was not correctly named. For example: the name should have been DemoModule and the incorrect name was ModuleDemo.

| improve this answer | |

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.