Zend Framework3 相似路由冲突
Zend Framework3 similar routes conflict
我正在使用 ZF3,在 module.config.php 文件 Post 模块中,我有这两条路线之一,
'create-post' => [
'type' => Literal::class,
'options' => [
// Change this to something specific to your module
'route' => '/post/create',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'create',
]
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
],
'post' => [
'type' => Segment::class,
'options' => [
// Change this to something specific to your module
'route' => '/post[/:postId]',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'show',
],
'constraints' => array(
'postId' => '\d{4}'
)
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
]
现在当我访问http://localhost:8080/post/create it works, but when I visit http://localhost:8080/post/32时,它不起作用。它说 404 错误,找不到页面。
非常感谢任何帮助。
根据@jon Stirling 对我的问题的评论,我更改了 post 路线的约束并且它起作用了。
已将 'postId' => '\d{4}' 更改为 'postId' => '\d{1,4 }'
'post' => [
'type' => Segment::class,
'options' => [
// Change this to something specific to your module
'route' => '/post[/:postId]',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'show',
],
'constraints' => array(
'postId' => '\d{1,4}'
)
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
]
我正在使用 ZF3,在 module.config.php 文件 Post 模块中,我有这两条路线之一,
'create-post' => [
'type' => Literal::class,
'options' => [
// Change this to something specific to your module
'route' => '/post/create',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'create',
]
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
],
'post' => [
'type' => Segment::class,
'options' => [
// Change this to something specific to your module
'route' => '/post[/:postId]',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'show',
],
'constraints' => array(
'postId' => '\d{4}'
)
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
]
现在当我访问http://localhost:8080/post/create it works, but when I visit http://localhost:8080/post/32时,它不起作用。它说 404 错误,找不到页面。
非常感谢任何帮助。
根据@jon Stirling 对我的问题的评论,我更改了 post 路线的约束并且它起作用了。
已将 'postId' => '\d{4}' 更改为 'postId' => '\d{1,4 }'
'post' => [
'type' => Segment::class,
'options' => [
// Change this to something specific to your module
'route' => '/post[/:postId]',
'defaults' => [
'controller' => Controller\PostController::class,
'action' => 'show',
],
'constraints' => array(
'postId' => '\d{1,4}'
)
],
'may_terminate' => true,
'child_routes' => [
// You can place additional routes that match under the
// route defined above here.
],
]