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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

creating a logout link


Go to End


10 Posts   14381 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, 190 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