Jump to:

23453 Posts in 18902 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » creating a logout link

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 6830 Views
  • ijasnijas
    Community Member
    1 Post

    Re: creating a logout link Link to this post


    I think this is more simple and helped me alot.

    // mysite/code/Page.php -> Page_Controller

       public function IsLoggedIn(){
             return true;

       public function CurrentUser(){
          return Member::currentUser();      

    // In your template File

       <% if IsLoggedIn %>
          <li id="logged-in" class="mainmenu">
             <% control CurrentUser %>
                <span>You are logged in as </span>
                   <% if FirstName && Surname %>
                      $FirstName $Surname
                   <% else_if FirstName %>
                   <% else %>
                   <% end_if %>
                (<a href="Security/logout" id="LogoutLink">Logout</a>)
             <% end_control %>
       <% else %>
          <li id="login" class="mainmenu"><a href="Security/login?BackURL=$Link">Login</a></li>
       <% end_if %>

  • Optic Blaze
    Community Member
    162 Posts

    Re: creating a logout link Link to this post


    When creating a logout link in Silverstripe 3.1 i got the following error:
    [Strict Notice] Non-static method Security::logout() should not be called statically ....

    Looked at the docs. And used the following in page.php Also created link in .ss template as per earlier posts on this topic

    public function logout($redirect = true) {
    $member = Member::currentUser();
    if($member) $member->logOut();

    This worked for me

Page: 1 2
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.