实例别名不打算在路由中使用,而是对 DI 有用的“快捷方式”。例如,假设您在模块事件上调用的方法中:
// get the di locator
$di = $e->getTarget()->getLocator();
// get instance by alias
$loginController = $di->get('login');
相反,要设置路由规则,您可以在配置文件中执行此操作:
// Setup for router and routes
return array(
'di' => array(
'instance' => array(
....
// Setup for router and routes
'Zend\Mvc\Router\RouteStack' => array(
'parameters' => array(
'routes' => array(
'default' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Application\Controller\IndexController',
'action' => 'index',
),
),
),
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\IndexController',
'action' => 'index',
),
),
),
),
),
),
我建议你阅读 Akrabat 的入门教程