0
votes

I was successful with getting Symfony CMF and Auto Routing Bundle (and a custom contoller) to load documents in the following manner (path):

.../category/article-name

This works fine. But I need something like this, easily achieved by standard Symfony2:

.../category/article-name/{page}

Where page is passed to a controller as a parameter, eg. $page = 2 -> controller processes content of the Article document to display only given page or $page = null -> (so no {page} parameter at all) - as above, but displayed is page default that is 1

How to make routing-auto bundle of the Symfony CMF to use parameters in routes?

So that the basic path is exactly as it is configured as in this Auto Routing Bundle configuration, but additionally I can use parameters passed to a controller, so that additional decisions can be made upon them. Any hints? Thanks!

My config for auto routing:

    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() of the Article Document just returns a parents (i.e. category) name. Here's part of this document content:

public function getRouteNodeCategory()
{
    return $this->parent->getTitle();
}
1

1 Answers

1
votes

This is not currently possible in the RoutingAutoBundle but it could be easily implemented.

The RoutingAutoBundle creates Route documents which extend the CMF's Route object. These Route objects do support variable patterns which allow you to specify dynamic paramters:

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

So we would just need to extend the mapping to include details on dynamic (variable) parameters in the URL.

Note also that the a new version of the routing auto bundle will soon be released which features a much better configuration format.

If you could create an issue detailing your use case, we will try and implement it for the 1.0 release.