Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » User log-in and redirect to different page

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

Page: 1 2 3 4
Go to End
Author Topic: 6675 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Re: User log-in and redirect to different page Link to this post

    Yes you can:

    in security -> underneath the checkbox 'go to admin area'

    it says:
    'Or select a Page to redirect to'

    select your redirect page.

  • balder
    Avatar
    Community Member
    14 Posts

    Re: User log-in and redirect to different page Link to this post

    Tried that, but when i select a page to redirect to the user logs in and is redirected to the frontend page i've choosen, while i want him to be redirected to that page but INSIDE the cms, so he can start editing his page as soon as he logs in. Does it make sense?
    Thanks for your help

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: User log-in and redirect to different page Link to this post

    Hi Balder

    all you need to do is change the way the redirect link is contructed, so this bit of code:

    //Get the page that is referenced in the group
    $Link = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->URLSegment;

    Becomes this:

    //Get the page that is referenced in the group
    $Link = "admin/show/$Group->LinkPageID";

    Untested but that should do it ;)

    Aram

    www.SSbits.com - SilverStripe Tutorials, Tips and other bits

  • balder
    Avatar
    Community Member
    14 Posts

    Re: User log-in and redirect to different page Link to this post

    OK, i solved it thanks to this thread: http://www.silverstripe.org/general-questions/show/257647

    ----------------
    The way to do this is to have the link be /admin/show/$ID of the page you want to redirect to. So I image you extract the Id from the TreeDropdownField and insert it into the redirector so change these lines:

    $Link = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->URLSegment;

    to this:

    $ID = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->ID;

    And this line:

    Director::redirect(Director::baseURL() . $Link);

    to this:

    Director::redirect(Director::baseURL() . "admin/show/" . $ID);

    ------------------------

    [edit]
    You were faster
    And that works by the way, so thanks a lot!

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: User log-in and redirect to different page Link to this post

    /\ My way is simple ;)

  • balder
    Avatar
    Community Member
    14 Posts

    Re: User log-in and redirect to different page Link to this post

    Just one more question to clean things up: when redirecting, the browser now displays a page with the following text:

    -----------------
    done
    Redirecting to /myurl/admin/show/86... (output started on /.../mysite/code/CustomLogin.php, line 10)
    --------------

    And then redirects.
    Is it possible not to display that page?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: User log-in and redirect to different page Link to this post

    Hmm yea I have had that before, but not sure if/how you can get rid of it :s

    Annoying...

  • balder
    Avatar
    Community Member
    14 Posts

    Re: User log-in and redirect to different page Link to this post

    Well that was easy
    I just deleted the following on CustomLogin.php, line 10, which i guess was a leftover from the code i copied ;)
    --------------
    echo 'done';
    --------------

    6675 Views
Page: 1 2 3 4
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.