Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6331743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:07:43+00:00 2026-05-24T18:07:43+00:00

I am trying with no luck to find a referrer object for use in

  • 0

I am trying with no luck to find a “referrer” object for use in my
controller. I expected there would be an object similar to the request
object with parameters specifying the _controller, _route and
arguments.

What I am trying to do is a language switcher action that redirects
the user to the same page in the new language. Something along the
lines of:

public function switchLangAction($_locale)
{
    $args = array();
    $newLang = ($_locale == 'en') ? 'fr' : 'en';

    // this is how I would have hoped to get a reference to the referrer request.
    $referrer = $this->get('referrer');
    $referrerRoute = $referrer->parameters->get('_route');
    $args = $referrer->parameters->get('args'); // not sure how to get the route args out of the params either!
    $args['_locale'] = $newLang;

    $response = new RedirectResponse( $this->generateUrl(
        $referrerRoute,
        $args
    ));

    return $response;
}

It’s also possible that there is another way to do this – I know in
rails there is the “redirect_to :back” method for example.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:07:44+00:00Added an answer on May 24, 2026 at 6:07 pm

    Why not changing the locale in the user’s session?

    First, define your locales in the router

    my_login_route:
        pattern: /lang/{_locale}
        defaults: { _controller: AcmeDemoBundle:Locale:changeLang }
        requirements:
            _locale: ^en|fr$
    

    Then, set the session

    namespace Acme\DemoBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class LocaleController extends Controller
    {
        public function switchLangAction($_locale, Request $request)
        {
            $session = $request->getSession();
            $session->setLocale($_locale);
            // ... some other possible actions
    
            return $this->redirect($session->get('referrer'));
        }
    }
    

    In all other controllers you should set the session variable yourself by calling

    $session->set('referrer', $request->getRequestUri());
    

    You could also probably make an event listener to set the session variable for every page automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to use the asp.net menucontrol but sadly without any luck. Here is
I am trying to find some examples but no luck. Does anyone know of
I have been trying to learn Yii without luck. I find Zend Framework, Kohana,
Trying to use regex refind tag to find the content within the brackets in
I'm trying to use XElement to find out the parent node of a child.
I'm trying to find download link for VS express 2005 but no luck. I
I'm trying to find a good XCode 4 tutorial out there that does the
I was trying to find an example about how to use TryScan , but
I'm trying to find a way to use the refresh method of jQuery ui
I been trying to find an Free/Open Source XML-FO processor that i could use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.