Magento 中 路由具体写法 */*/*
路由具体分析如下:
$routePieces = explode('/', $data);
$route = array_shift($routePieces);
if ('*' === $route) {
$route = $this->_getRequest()->getRouteName();
}
$this->_setRouteName($route);
$controller = '';
if (!empty($routePieces)) {
$controller = array_shift($routePieces);
if ('*' === $controller) {
$controller = $this->_getRequest()->getControllerName();
}
}
$this->_setControllerName($controller);
$action = '';
if (!empty($routePieces)) {
$action = array_shift($routePieces);
if ('*' === $action) {
$action = $this->_getRequest()->getActionName();
}
}
$this->_setActionName($action);
可以看到如果路由是 */*/*
的模式的话,会自动会获取对应的值,也就是
$route = $this->_getRequest()->getRouteName();
$controller = $this->_getRequest()->getControllerName();
$action = $this->_getRequest()->getActionName();
具体代码在 vendor/magento/framework/Url.php 第 506 行