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.

General Questions /

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

creating a logout link


Go to End
Reply


10 Posts   7096 Views

Avatar
ijasnijas

Community Member, 1 Post

24 December 2010 at 1:17am

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 %>

:)

Avatar
Optic Blaze

Community Member, 165 Posts

21 December 2013 at 3:29am

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

Go to Top