【发布时间】:2014-07-12 15:34:45
【问题描述】:
这个路由器出了什么问题:
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'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]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
'api' => array(
'type' => 'Literal',
'options' => array(
'route' => '/api',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Api',
'action' => 'index',
),
'may_terminate' => true,
'child_routes' => array(
'post' => array(
'type' => 'Segment',
'options' => array(
'route' => '/post/:id',
'constraints' => array(
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Api',
'action' => 'post',
),
),
),
'page' => array(
'type' => 'Segment',
'options' => array(
'route' => '/page/:name',
'constraints' => array(
'name' => '[a-zA-Z]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Api',
'action' => 'page',
),
),
),
),
),
),
),
我无法路由到 http://example.com/api/post/0 和 http://example.com/api/page/pagename ?带有 404 的 zend 框架 2 响应 - 找不到页面 - “请求的 URL 无法通过路由匹配”。这两条路由在路由器定义中。
【问题讨论】:
-
我发现了一个问题,'may_terminate' 应该在选项之外。
-
请发帖回答
-
我必须等待 10 小时才能回答我的问题。 10小时后应该会出现。不同之处在于 'api' 路线 - 'may_terminate' 应该在 'options' 数组之外,所以我们必须在 'may_terminate' 之前添加 ) 并在最后删除一个 )。