Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You must store an array of your route attributes in the session instead of a single url.</p> <pre><code>/** * You should set the 'referrer' in every controller in your application. This * should probably be handled as an event to save all the hassle. */ public function anyAction(Request $request) { $request-&gt;getSession()-&gt;set('referrer', $request-&gt;attributes-&gt;all()); // ... } /** * Your locale changing controller */ public function localeAction($locale, Request $request) { if($request-&gt;hasSession()) { $session = $request-&gt;getSession(); $session-&gt;setLocale($locale); $route_params = $session-&gt;get('referrer'); // Get the route name $route = $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); $route_params = array_diff_key($route_params, $ignore_params); $url = $this-&gt;get('router')-&gt;generate($route, $route_params); return $this-&gt;redirect($url); } } </code></pre> <p>For future reference and to anyone stumbling over this: you don't have to store the <code>referrer</code> attribute in your session by setting it in EVERY controller. You can retrieve the previous url from the <code>headers</code> property:</p> <pre><code>$request-&gt;headers-&gt;get('referer'); // Single 'r' everywhere! </code></pre> <p>For additional info, consult:</p> <ul> <li>Symfony2 <code>Request</code> class on <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php" rel="nofollow">github</a></li> <li>Symfony2 <code>ParameterBag</code> class on <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/ParameterBag.php" rel="nofollow">github</a> </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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