We are trying to create menu in admin panel in magento 2.4. We have added the menu successfully and configuration link of module is working fine. But when we add some other controller and its link, we are getting the error "Invalid security or form key. Please refresh the page.".
So please let us know how can we create customer controller and its link.
Hi @supportopeadb2 , You can create your custom controller with the below steps.
Here is the solution for creating a custom controller. Step 1: Create a menu configuration file. Step 2:After completing it. Clear the Magento cache and go to the admin panel. Step 3: Create an admin controller file. you have to create a separate file for each action of admin in the Controller/Adminhtml folder in M2. app/code/[vendor_name]/[module_name]/Controller/Adminhtml/[menu/submenu]/index.php
class Index extends \Magento\Backend\App\Action
* Hello test controller page.
* @return \Magento\Backend\Model\View\Result\Page
public function execute()
echo __('Hello World.');
* Check Permission.
* @return bool
protected function _isAllowed()
Step 4: Now, create a route configuration file for admin. app/code/[vendor_name]/[modle_name]/etc/adminhtml/routes.xml
If you are facing this error while adding menus then there are multiple reasons for this error to occur.
1. Check your module file for errors in the logs file. (search in the log files e.g. magento_root_directory/var/log/execption.log debug.log system.log) 2. Make sure that you have made the admin route. 3. Check your controller for any syntax error. 4. If you are making a grid then it is possible that there is any database connectivity error(records are missing). or etc.
Check for these solutions and if you still need any help regarding this feel free to ask.