当试图通过调用来组装路由时
return $this->redirect()->toRoute('application');
在我的控制器中,我得到以下异常:
Zend'Mvc'Router'Exception'RuntimeException
File: library'Zend'Mvc'Router'Http'Part.php:181
Message: Part route may not terminate
路由配置如下:
'routes' => array(
'application' => array(
'type' => '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(
'__NAMESPACE__' => 'Application'Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard',
),
),
),
),
是否需要将controller/action
路由作为路由/
的子路由?当我这样配置它时,它就工作了。当我使用路由[/[:controller[/[:action[/]]]]]
(带可选的前导斜杠)时,它适用于某些程序集,但不适用于所有程序集,并且它们都以与上述相同的方式调用,部分来自其他模块。
错误已经告诉您问题:您在当前路由中缺少may_terminate
选项。因此,您不能通过返回redirect()
插件返回值来short-circuit
它。
只需添加一个
'may_terminate' => true
到您的路由配置(可能到所有路由配置)。