我成功地让 Symfony CMF 和 Auto Routing Bundle(以及自定义控制器)以下列方式(路径)加载文档:
.../category/article-name
这工作正常。但我需要这样的东西,可以通过标准 Symfony2 轻松实现:
.../category/article-name/{page}
页面作为参数传递给控制器的位置,例如。$page = 2 -> 控制器处理文章文档的内容以仅显示给定页面或 $page = null -> (所以根本没有 {page} 参数) - 如上所述,但显示的是页面默认值,即 1
如何使 Symfony CMF 的 routing-auto 捆绑包在路由中使用参数?
因此基本路径与此 Auto Routing Bundle 配置中的配置完全相同,但另外我可以使用传递给控制器的参数,以便可以对它们做出额外的决定。有什么提示吗?谢谢!
我的自动路由配置:
MyApp\MyCmsBundle\Document\Article:
content_path:
#fixed path of all categories and therefore articles
articles_categories_path:
provider: [specified, { path: /cms/routes }]
exists_action: use
not_exists_action: throw_exception
#category path
category_path:
provider: [content_method, { method: getRouteNodeCategory }]
exists_action: use
not_exists_action: throw_exception
#article name
content_name:
provider: [content_method, { method: getTitle }]
exists_action: [auto_increment, { pattern: -%d }]
not_exists_action: create
MyApp\MyCmsBundle\Document\ArticlesCategory:
content_path:
#fixed path of all categories and therefore articles
articles_categories_path:
provider: [specified, { path: /cms/routes }]
exists_action: use
not_exists_action: throw_exception
#category name
content_name:
provider: [content_method, { method: getTitle }]
exists_action: use
not_exists_action: create
文章文档的getRouteNodeCategory() 只返回一个父类(即类别)名称。以下是本文档内容的一部分:
public function getRouteNodeCategory()
{
return $this->parent->getTitle();
}