Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[solved] Director::redirect( The actual page but with the current member locale )


Go to End


2 Posts   2061 Views

Avatar
VRoxane

Community Member, 42 Posts

18 March 2011 at 3:28am

Edited: 18/03/2011 3:29am

Hello !

On log in, I want the current page viewed to be "translated" (the user is redirected to the page in his own language/locale).
I already put this in the Page.php :

	$member = Member::currentUser();
		if($member && $member->Locale) {
			//Translatable::set_locale($member->Locale);
			Translatable::set_current_locale($member->Locale);

and when I log in, the menus get translated, but not the content.

So, I got this code on the amazing SSbits site :
http://www.ssbits.com/snippets/2010/customize-the-redirect-after-a-successful-member-login/

And I'm trying to modify it so when I log in, the site refreshes to the same page (ex: /contact), but with my locale defined as the current locale (/contact?locale=en_GB) so I would be redirected to /contact-en-gb.

The last line is what I invented wrote myself :

 /// In LoginLocale.php :
class LoginLocale extends MemberLoginForm {
    public function dologin($data) {
        parent::dologin($data);
        if( Director::redirected_to() and Member::currentUserID() ) {
            $this->controller->response->removeHeader('Location');
			$member = Member::currentUser();
			$member_locale = $member->Locale;
            Director::redirect(Director::baseURL() . Director::get_current_page()->UrlSegment . "?locale=" . $member_locale);
        }
    }
}


/// And in _config :

	Object::useCustomClass('MemberLoginForm', 'LoginLocale');

I manage to set the locale, but the Current Page Url doesn't show anything -> I get to the homepage.

Can somebody help me with the last line ?

Avatar
VRoxane

Community Member, 42 Posts

18 March 2011 at 8:47pm

Here's the solution :

For the last line, you can use this (what I managed to write without really knowing what I was doin') :

$params    = Director::urlparams();
Director::redirect(Director::baseURL() . $params['URLSegment'] . "?locale=" . $member_locale);

or this (it's shorter and very simple... that's the bit of code I was searching. Thanks to Zauberfisch on #silverstripe !) :

Director::redirect(Director::get_current_page()->Link() . "?locale=" . $member_locale);