简体   繁体   English

在Symfony2中处理类似CMS的项目的路由的最佳方法是什么

[英]What is the best way to handle routing for CMS-like project in Symfony2

I'm trying to build an Symfony2 application, that have CMS features. 我正在尝试构建一个具有CMS功能的Symfony2应用程序。 I've got three entities (among others) which are : Page , Category , Post (classic ones, huh ?) 我有三个实体(其中包括): PageCategoryPost (经典的,是吧?)

I would like to have the following routing : 我想有以下路由:

Page : /{slug} (slug is a Page entity field) 页: / {slug} (slug是一个Page实体字段)

Category : /{slug} (slug is a Category entity field) 类别: / {slug} (slug是一个Category实体字段)

Post : /{slug} (slug is a Post entity field) 发布: / {slug} (slug是一个Post实体字段)

However, this will never work, because Symfony2 router, will match the first route that corresponds to the /{slug} pattern. 但是,这将永远不会起作用,因为Symfony2路由器将匹配与/{slug}模式对应的第一条路由。

I would like to know, what is the best pratice to handle these cases. 我想知道,处理这些案件的最佳实践是什么。 I'm aware of Symfony CMF, but I do not want use this kind of massive tool (as it contains too many bundles which I'm not willing to use). 我知道Symfony CMF,但我不想使用这种大型工具(因为它包含太多我不愿意使用的软件包)。

Thanks in advance for your answers 提前感谢您的回答

You will have to use a custom route loader to do this, check the cookbook article: 您将不得不使用自定义路由加载器来执行此操作,请查看cookbook文章:

http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html

The CMF project uses its own dynamic router which you could use without the full CMF stack also: CMF项目使用自己的动态路由器,您可以在没有完整CMF堆栈的情况下使用它:

http://symfony.com/doc/current/cmf/bundles/routing/dynamic.html http://symfony.com/doc/current/cmf/bundles/routing/dynamic.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM