Zend 框架 2 child_route
Zend framework 2 child_route
我正在尝试为我的索引页创建一个 child_route,但不幸的是它没有路由到该操作。
路由脚本是:
'home' => array(
'type' => 'literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
"may_terminate" => true,
"child_routes" => array(
"support" => array(
"type" => "segment",
"options" => array(
"route" => "/support",
"defaults" => array(
'controller' => 'Application\Controller\Index',
'action' => 'support',
),
),
),
),
),
),
我还在同一个 ZF2 项目的另一个模块中使用了相同的结构。你能帮我提示一下我的错误吗?
在另一个模块上工作的类似路由配置是这个:
"post" => array(
"type" => "literal",
"options" => array(
"route" => "/blog",
"defaults" => array(
"controller" => "Blog\Controller\List",
"action" => "index",
),
),
"may_terminate" => true,
"child_routes" => array(
"detail" => array(
"type" => "segment",
"options" => array(
"route" => "/:id[/]",
"defaults" => array(
"action" => "detail",
),
"constraints" => array(
"id" => "[1-9]\d*"
),
),
),
"admin" => array(
"type" => "segment",
"options" => array(
"route" => "/admin[/]",
"defaults" => array(
"action" => "admin",
),
),
),
),
),
谢谢!
不要将子路由添加到主路由。我知道这似乎是一种合乎逻辑的方法,但通常以混乱和不必要的冗长告终。
您为 //support
设置的路线可能不是您的本意。尽管删除初始斜杠应该可以解决问题,但我建议将您的支持路线从 home 下移出,然后它应该可以正常工作。
(注意:子路由一般都可以,我只是喜欢把home路由分开。)
我正在尝试为我的索引页创建一个 child_route,但不幸的是它没有路由到该操作。 路由脚本是:
'home' => array(
'type' => 'literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
"may_terminate" => true,
"child_routes" => array(
"support" => array(
"type" => "segment",
"options" => array(
"route" => "/support",
"defaults" => array(
'controller' => 'Application\Controller\Index',
'action' => 'support',
),
),
),
),
),
),
我还在同一个 ZF2 项目的另一个模块中使用了相同的结构。你能帮我提示一下我的错误吗?
在另一个模块上工作的类似路由配置是这个:
"post" => array(
"type" => "literal",
"options" => array(
"route" => "/blog",
"defaults" => array(
"controller" => "Blog\Controller\List",
"action" => "index",
),
),
"may_terminate" => true,
"child_routes" => array(
"detail" => array(
"type" => "segment",
"options" => array(
"route" => "/:id[/]",
"defaults" => array(
"action" => "detail",
),
"constraints" => array(
"id" => "[1-9]\d*"
),
),
),
"admin" => array(
"type" => "segment",
"options" => array(
"route" => "/admin[/]",
"defaults" => array(
"action" => "admin",
),
),
),
),
),
谢谢!
不要将子路由添加到主路由。我知道这似乎是一种合乎逻辑的方法,但通常以混乱和不必要的冗长告终。
您为 //support
设置的路线可能不是您的本意。尽管删除初始斜杠应该可以解决问题,但我建议将您的支持路线从 home 下移出,然后它应该可以正常工作。
(注意:子路由一般都可以,我只是喜欢把home路由分开。)