【发布时间】:2015-07-21 04:20:34
【问题描述】:
我正在尝试访问 站点名称/news/id/1,但它给了我这个错误。过去 30 分钟我一直在尝试修复它,但我无法弄清楚我做错了什么。
配置:
//...
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]/id/[/:id]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
),
),
),
),
),
'news' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/news/id[/:id]',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'news',
),
),
),
),
),
//...
【问题讨论】:
-
我以前从未使用过 Zend 路由,但
[:controller看起来不对。你确定它不应该是[:controller]吗?另外,[/:action]id中的id在路由中单独做什么?这条路线对我来说只是关闭。 -
应该是/id/然后才是实际的id
标签: php zend-framework routing zend-framework2 url-routing