![]() |
|
Snippets |
|
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.
Comments on this snippet
Great snippet, thanks Fabien. This will prove very useful.
Where do I have to put this one? In my config.php? Or Can I add it in one of my .yml-files in the config folder?
myCultureFilter filter
myapp/config/filters.yml
cultureFilter: class: myCultureFiltermyapp/lib/myCultureFilter.class.php
Since r2663, you can directly use the
:sf_culturevariable in your routes; it is automatically set to the user culture, and it removes the need for a filter.For the language-dependent routing to work inbound, you have to add a filter anyway. It will check if the
sf_culturerequest parameter is different from the current user culture, and if so, change the user culture. Something like:does this (except for comments my francois Z.) works on current stable ( 0.6.3 ) coz i cannot get it to work, the culture doesn't show in generated urls
Hi Fabien!
I have a challenger, that i cann't solved. Is about URLs (routing) and I18N. I need have URLs for each culture: example : site.com/goodday site.com/buendia site.com/bongiorno
I think that, site.com/en/goodday site.com/es/goodday site.com/it/goodday
is a partial solution, because, someone with culture spanish o italian, do not know what means "goodday"
Someone in the Forum, post: regla: url_es: /hola url_en: /hello params: { .... }
Other say: have 2 URL are a same routing rule "@home" and point to same module/action. I think a solution is have a routing.yml (default), or routing.en.yml and routing.es.yml and routing.it.yml
I'am relative new in symfony, i build my first project, and this is a really nice feature for Symfony.
Cheers
Roberto (puentesdiaz@gmail.com)