0

我成功地让 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();
}
4

1 回答 1

1

这目前在 RoutingAutoBundle 中是不可能的,但它可以很容易地实现。

RoutingAutoBundle 创建扩展 CMF 的 Route 对象的 Route 文档。这些 Route 对象确实支持允许您指定动态参数的可变模式:

https://github.com/symfony-cmf/RoutingBundle/blob/1.2/Model/Route.php#L53

因此,我们只需要扩展映射以在 URL 中包含有关动态(可变)参数的详细信息。

另请注意,新版本的路由自动包将很快发布,它具有更好的配置格式。

如果您可以创建一个详细说明您的用例的问题,我们将尝试在 1.0 版本中实现它。

于 2014-07-09T18:41:55.203 回答