Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Gilden, thanks a lot for idea, but it's doesn't work anyway...</p> <p>Here is the controller LOCALE SWITCHER:</p> <pre><code>class LocaleController extends Controller { public function changeAction($locale, Request $request) { if ($request-&gt;hasSession()) { $session = $request-&gt;getSession(); $session-&gt;setLocale($locale); $route_params = $session-&gt;get('jet_referrer'); $route_name = $route_params['_route']; // Some parameters are not required to be used, filter them // by using an array of ignored elements. $ignore_params = array('_route' =&gt; true, '_controller' =&gt; true, '_template_default_vars' =&gt; true); $route_params = array_diff_key($route_params, $ignore_params); $url = $this-&gt;get('router')-&gt;generate($route_name, $route_params); return $this-&gt;redirect($url); } } } </code></pre> <p>Here is the controller of BUSINESS LOGIC:</p> <pre><code>/** * @Route("/{_locale}") */ class TestController extends Controller { /** * @Route("/", name="_test") * @Template() */ public function indexAction(Request $request) { $request-&gt;getSession()-&gt;set('jet_referrer', $request-&gt;attributes-&gt;all()); return array(); } /** * @Route("/hello/{name}", name="_test_hello") * @Template() */ public function helloAction($name, Request $request) { $request-&gt;getSession()-&gt;set('jet_referrer', $request-&gt;attributes-&gt;all()); return array('name' =&gt; $name); } } </code></pre> <p>Regarding IGNORED params for array_key_diff()...</p> <pre><code>_controller _locale _route _template _template_default_vars _template_vars </code></pre> <p>I've tried to include few of them for the new route generation, but with no luck... Don't understand what is going on...</p> <p>It's seems just a hack... Do we have more sofisticated way to realize this simple feature in Symfony2 ?? RAW PHP allows me to do that much &amp; much more easily...</p> <p>Thanks again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload