Jump to:

23490 Posts in 18996 Topics by 2878 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: 6894 Views
  • ijasnijas
    Avatar
    Community Member
    1 Post

    Re: creating a logout link Link to this post

    Hi,

    I think this is more simple and helped me alot.

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

       public function IsLoggedIn(){
          if(Member::currentUserId()){
             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>
                <strong>
                   <% if FirstName && Surname %>
                      $FirstName $Surname
                   <% else_if FirstName %>
                      $FirstName
                   <% else %>
                      $Email
                   <% end_if %>
                </strong>
                (<a href="Security/logout" id="LogoutLink">Logout</a>)
             <% end_control %>
          </li>
       <% else %>
          <li id="login" class="mainmenu"><a href="Security/login?BackURL=$Link">Login</a></li>
       <% end_if %>

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: creating a logout link Link to this post

    Hi,

    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->redirect('home/');
    }

    This worked for me

    6894 Views
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.