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

Page Controller view permission to Logged in users


Go to End


3 Posts   1024 Views

Avatar
Praveen

Community Member, 49 Posts

20 May 2015 at 4:34pm

I want to know there is a better way to do it
I want to restrict a page to only logged in users.
Finally I am using below code, which works to me

class ProfilePage_Controller extends Page_Controller {
 public function init()
	{
		
		parent::init();
                $member = Member::currentUser();
		if(!$member) Security::permissionFailure(); 
    }
}

Avatar
Pyromanik

Community Member, 419 Posts

20 May 2015 at 10:14pm

public funciton canView(){return Member::currentUserID();}

Or if it's a SiteTree page (which it looks like it is) just set it as such in the CMS (Access tab).

Avatar
Praveen

Community Member, 49 Posts

29 May 2015 at 8:57pm

Edited: 29/05/2015 8:57pm

public function canView(){return Member::currentUserID();}

Thanks