I'm trying to figure out why my custom controller is redirecting to the sales dashboard.
The way I understand it when Magento has an issue with either the form key or the routes, it just redirects to the default page (in this case the admin sales dashboard). It seems that I am having an issue as this happens for one of my controllers.
I should mention that there is no error as well, normally I get "invalid security key" or something like that but in this case it had none.
/Controller/Adminhtml/Test/Index.php
namespace Companyname\TestModule\Controller\Adminhtml\Test;
class Index extends \Magento\Backend\App\Action
{
protected $_publicActions = ['index'];
public function __construct
(
\Magento\Backend\App\Action\Context $context
)
{
parent::__construct($context);
}
public function execute()
{
die("It works.");
}
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Companyname_TestModule::test');
}
}
/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="test" frontName="test">
<module name="Companyname_TestModule"/>
</route>
</router>
</config>
URL function:
public function getURL()
{
$route = "test/test/index";
$params = [];
return $this->getUrl($route, $params);
}
truefrom isAllowed() just to see if that fixes your issue$this->_authorization->isAllowed('Companyname_TestModule::test')but you haven't defined that resource in acl.xml. Setting isAllowed to true will help you narrow down the source of the problem.