If you’ve spent anytime doing Magento 1 module development, you’re probably familiar with the _validateControllerClassName
method. This method is where Magento 1 generates and validates paths to possible controller class matches during routing.
This method is gone in Magento 2 – partially due to the PSR-0 autoloader being the standard, even for controller classes, and partially due to refactoring.
Here’s a few similar spots in Magento 2 that can help you track down a non-matching route configuration – you may want to read through my article on Magento 2’s routing and M-V-VM system if you’re a little unclear on what we’re talking about.
First, there’s Magento/Framework/App/Router/Base
, where Magento searches for a module match. If your module doesn’t show up in $modules
, something’s amiss.
#File: lib/internal/Magento/Framework/App/Router/Base.php
protected function matchAction(MagentoFrameworkAppRequestInterface $request, array $params)
{
//
$modules = $this->_routeConfig->getModulesByFrontName($moduleFrontName);
//
}
Then there’s MagentoFrameworkAppRouterActionList
#File: lib/internal/Magento/Framework/App/Router/ActionList.php
public function get($module, $area, $namespace, $action)
{
//...
$fullPath = str_replace(
'_',
'\',
strtolower(
$module . '\controller' . $area . '\' . $namespace . '\' . $action
)
);
if (isset($this->actions[$fullPath])) {
return is_subclass_of($this->actions[$fullPath], $this->actionInterface) ? $this->actions[$fullPath] : null;
}
//...
}
Checking the value of $this->actions
and $fullPath
can help you find common typo mistakes.