Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Snippets tagged "i18n routing" Snippets tagged "i18n routing"

How to have common parameters for every route

Let's take an example. You want to have the user culture in front of each of your URL.

So, your routing configuration look like something like that:

page:
  url: /:culture/:page
  params: ...

article:
  url: /:culture/:year/:month/:day/:slug
  params: ...

...

This is the easy part. But now, every time you call url_for() or link_to() you have to pass the culture parameter.

For such situations, there is a better way. The routing has a special configuration parameter named sf_routing_defaults that you can set with default values:

sfConfig::set('sf_routing_defaults', array('culture' => 'en'));

And now, the culture parameter will automatically added to the parameters that you pass to the url_for() or link_to() helpers.

by Fabien Potencier on 2006-08-23, tagged i18n  routing 
(7 comments)