php - 为什么 Zend 框架中的正则表达式路由不起作用?
问题描述
几个月前,我在使用 ZF3 的网站上工作,并且网站运行正常。现在我在不同的服务器上配置这个站点并且得到一些 url 的 404 错误。
配置代码是:
'router' => [
'routes' => [
'announcements' => [
'type' => Segment::class,
'options' => [
'route' => '/announcements[/:id][/:action]',
'constraints' => [
'id' => '[0-9]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
],
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
http://example.com/announcements =>工作
http://example.com/announcements/2 =>工作
http://example.com/announcements/send =>不工作
那么有人可以建议我如何解决它吗?
谢谢
解决方案
如果id
URL 中的 完全是可选的,那么我建议实际上有三个路由:
'route' => '/announcements[/:id][/:action]'
'route' => '/announcements[/:id]'
'route' => '/announcements[/:action]'
它们实际上是三个独立的端点,因为id
和action
可能同时出现、单独出现或根本不出现。
推荐阅读
- functional-programming - 是否可以检查当前的延续是否正在终止?
- firebase - 依赖于文档参考的 Firestore 访问规则
- tsql - 在预期条件的上下文中指定的非布尔类型的表达式,靠近“tblProje”
- d3.js - 使用 D3 使折线图角度更平滑
- r - 如何删除非常细的条形图轮廓/边框
- python - 如何通过聚合从组中删除 Pandas 中的嵌套列名?
- vue.js - 水平对齐
来自 Vuetify - php - 用户在 PHP 中向汽车网站上传广告
- oracle-apex - Oracle APEX - 使用重定向到页面时该值不会结转
- swift - 数学公式迅速