-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi,

hm, yes i think this is what i thought. we did it that way but we have
extremly few routes in our project.
on the view layer, its easy as we just wrote a small snipped for that
element that is included in the base layout.

maybe somebody else knows how to generate the current route but with a
different locale generically? sounds like an important use case for
sites that are multilanguage.

cheers,david

Am 10.05.2011 20:39, schrieb theinterned:
> On the other point: I am not sure what you mean by your suggestion - I
> you suggesting that every controller action pass down a 'switched url'
> of itself to be rendered by the view? That seems like a lot to
> maintain. I am new to Symfony 2; maybe there is an elegant way to
> achieve this?
> 
> On May 10, 11:56 am, theinterned <ned...@gmail.com> wrote:
>> I solved this.
>>
>> I found the $router->match() method, which I am using against a
>> cleaned up version of the $request->server->get('HTTP_REFERER'). This
>> gives me the route parameters I need to generate my redirect route.
>>
>> Here is the completed action:
>>
>>     public function switchLangAction($_locale)
>>     {
>>         $newLang = ($_locale == "en") ? "fr" : "en";
>>
>>         $request = $this->get('request');
>>         $router = $this->get('router');
>>         $domain = $request->server->get('HTTP_HOST');
>>         $referrer = $request->server->get('HTTP_REFERER');
>>
>>         // remove the protocol
>>         $referrer = preg_replace(';\b((ftp|https?)://)+?\b;', '',
>> $referrer);
>>         // remove the domain
>>         $referrer = str_replace($domain, '', $referrer );
>>         // remove the controller
>>         $referrer = str_replace($request->getBaseUrl(), '',
>> $referrer);
>>         // remove the query string
>>         $referrer = preg_replace('/\?.*/', '', $referrer);
>>         // match the resulting cleaned up route
>>         $referrerParams = $router->match( $referrer );
>>         // pluck the _route out of the params
>>         $referrerRoute = $referrerParams['_route'];
>>         unset($referrerParams['_route']);
>>         // switch the locale
>>         $referrerParams['_locale'] = $newLang;
>>
>>         $response = new RedirectResponse( $this->generateUrl(
>>             $referrerRoute,
>>             $referrerParams
>>         ));
>>         return $response;
>>     }
>>
>> On May 9, 1:01 pm, Matt <matthieu.o.vac...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Hi,
>>
>>> This is how I did it:
>>
>>> public function changeLocaleAction($locale)
>>> {
>>>     if ($this->request->hasSession())
>>>         $this->session->setLocale($locale);
>>
>>>     $referer = $this->request->server->get('HTTP_REFERER');
>>>     if (!isset($referer))
>>>         $referer = $this->generateUrl('index');
>>
>>>     return new RedirectResponse($referer);
>>
>>> }
>>
>>> I'm not sure if it is the best to do it way but it works for me in my use
>>> cases.
>>
>>> Regards,
>>> Matt
> 

- -- 
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3KXKwACgkQqBnXnqWBgIsWSQCfbgjOF00tQmRzCl/QvSicSD5j
ZUIAnAiX2oMNvf0A6s6hOtBA/uTisJef
=45v0
-----END PGP SIGNATURE-----

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to