Routing for category tree(类别树的路由)
问题描述
我正在使用 Tree 学说类别树的扩展,并希望有如下路线:
I am using the Tree doctrine extension for a category tree and would like to have routes like:
/cat/subcat1/subcat2/subcat3
我可以这样定义路线
/{cat}
/{cat}/{subcat}
/{cat}/{subcat}/{subcat2)
etc...
但是有没有更优雅和通用的方法来实现它?一个可以接受无限数量的关卡的系统?
But is there a more elegant and general way of implementing this? A system that can accept an unlimited number of levels?
推荐答案
你可以做的是在你的路由参数中接受斜线(仅适用于这个路由).它涉及您不能将任何其他参数排队,因为斜线分隔符将被视为类别参数的一部分...
What you can do is accepting slashes in your routing parameters (for this route only). It involves that you can't queue any other parameter as slash separator will be seen as being part of category parameter...
那么,如何管理路由参数中的斜线:
So, how to manage slashes in a routing parameter :
_hello:
pattern: /category/{category}
defaults: { _controller: AcmeDemoBundle:Demo:category }
requirements:
category: ".+"
调用 /category/cat1/sub1/sub2
将调用 DemoController::categoryAction($category)
方法,并将 'cat1/sub1/sub2' 作为 $category 参数.只需使用您自己的代码来解码!
Calling /category/cat1/sub1/sub2
will call DemoController::categoryAction($category)
method with 'cat1/sub1/sub2' as $category parameter. Just use your own code to decode !
在官方文档中找到的代码示例:http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html
Code sample found on official doc : http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html
这篇关于类别树的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:类别树的路由


- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Laravel 仓库 2022-01-01