开发者

Redirect into SilverStripe's pages

开发者 https://www.devze.com 2023-01-01 01:46 出处:网络
I\'m trying to set up a redirect on my SilverStripe site. I have created my own module, and now I want the user to be redirected to that after log in.

I'm trying to set up a redirect on my SilverStripe site.

I have created my own module, and now I want the user to be redirected to that after log in.

I've tried with Director::redirect($Url_base . 'myModule'), but it do开发者_开发技巧esn't work.

Does anyone have any suggestions?


Try this: http://www.ssbits.com/customize-the-redirect-after-a-successful-member-login/


I did something like this:

class MyLoginForm extends MemberLoginForm {
    public function dologin($data) {
        parent::dologin($data);
        if (Director::redirected_to() && $Member = Member::currentUser()) {
            $this->controller->response->removeHeader('Location');
            if ($Member->Email == 'admin') {
                $destination = '/admin';
            } else {
                $destination = '/user/' . $Member->Username;
            }
            Director::redirect($destination);
        }
    }
}

If it is the admin user I redirect them to /admin. If it is another user I redirect them to /user/username.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号