Skip to content
cammanderson edited this page Sep 13, 2011 · 1 revision

Routing provides you the ability to map certain urls to request parameters and different URL's that exist in the CMS. This helps you create much friendlier looking URL's or even redirect to different pages/controllers.

Background

The simplest way to handle passing variables around through URL's is using the GET request (e.g. my-page/example?id=1). This often is the fastest way to have information transferred in the URL for processing in your request.

Using Routing for CMS Pages

Using Symfony2 Router, you can add to a routing.yml to create a new named route. This will contain the information about the URL and how to map parameters.

Importantly, you want to set the defaults to call the default controller for rendering pages, and you need to specify the {url}.

Route YML

designer:
    pattern:   /{url}/designer-profile/{slug}
    defaults:  { _controller: flint_cms.controller.default:indexAction }

You can then link to this page from the view and access the slug under the request parameters. This can then be listened to from Listeners or views.

Linking from twig fragment template

<h3>Designers</h3>
<ul>
    {% for designer in designers %}
    <li><a href="{{ path('designer', {'url': nav.url(node), 'slug': designer.slug}) }}">{{ designer.name }}</a></li>
    {% endfor %}
</ul>
Clone this wiki locally