Php zend framework 3段路由不';行不通
我有以下module.config.php:Php zend framework 3段路由不';行不通,php,http,zend-framework,routes,zend-framework3,Php,Http,Zend Framework,Routes,Zend Framework3,我有以下module.config.php: return [ 'router' => [ 'routes' => [ 'landingpage' => [ 'type' => Segment::class, 'options' => [ 'route' => '/landingpage[/:action/:i
return [
'router' => [
'routes' => [
'landingpage' => [
'type' => Segment::class,
'options' => [
'route' => '/landingpage[/:action/:id]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z0-9_-]*'
],
'defaults' => [
'controller' => Controller\LandingPageController::class,
'action' => 'index'
]
],
'may_terminate' => true,
]
]
],
'controllers' => [
'factories' => [
Controller\LandingPageController::class => LandingPageControllerFactory::class
]
],
'service_manager' => [
'invokables' => [
'LandingPage\Service\LandingPageService' => 'LandingPage\Service\LandingPageService'
]
]
];
我尝试使用以下路线,但不起作用:
如果我使用以下路线,它会起作用:
如果我使用上一条路线与a/它不起作用:
如果你需要更多信息,请告诉我。
谢谢。路线声明中有一个双斜杠:路线由
/landingpage/
匹配,后跟/:action/:id
。如果删除此双斜杠,管线将按预期工作
'route'=>'/landingpage[/:action/:id]',
此外,我建议您修改路由声明,使id成为可选的:
'route'=>'/landingpage[/:action[/:id]]',
'约束'=>[
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id'=>”[a-zA-Z0-9_u-]+'
]
测试:
配置
“登陆页面”=>[
'type'=>段::类,
“选项”=>[
“路由”=>“/landingpage[/:action[/:id]]”,
'约束'=>[
“行动”=>“[a-zA-Z][a-zA-Z0-9_u-]*”,
“id”=>“[a-zA-Z0-9_u-]*”
],
“默认设置”=>[
'controller'=>controller\IndexController::class,
'操作'=>'索引'
]
],
“may_terminate”=>true,
],
索引控制器:
公共函数索引(){
印刷品
呼叫/landingpage/show
数组
(
[控制器]=>应用程序\控制器\索引控制器
[行动]=>展示
)
呼叫/landingpage/show/1CGe2cveQ
数组
(
[控制器]=>应用程序\控制器\索引控制器
[行动]=>展示
[id]=>1CGe2cveQ
)
如果启用了配置缓存,请不要忘记清除它;)谢谢您的回答,但没有解决问题!我已经按照您所说的那样尝试了,但没有成功。从结果中可以看出,路由是正确的,工作正常。如果您的代码仍然不工作,那么问题出在其他地方。您清除了缓存吗?问题是什么错误消息?您能粘贴合并的配置吗?谢谢您的帮助!我会在尝试您所说的内容后立即更新帖子。如何清除配置缓存?最好的解决方案是禁用配置缓存(已解释),或者您可以删除文件夹数据/cache