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.

Customising the CMS /

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

Accessing Userdata


Go to End


3 Posts   733 Views

Avatar
Calli

Community Member, 3 Posts

1 May 2015 at 12:12am

Hello

My googling has yielded no results, thus I turn to you.
I've got a Silverstripe setup with an extended Member-class and it's own database table. I now want to create an external interface for accessing data stored in said table. Since this is my first confrontation with Silverstripe I'm rather stumped as to how to achieve this.
What I've tried:

require_once("../sapphire/core/Core.php");
if(Member::currentUserID())

The function exists and can be called, but never returns anything but 0 and does not enter the if (I am logged in however).
Also, I don't want to create a subpage on the site for this. Is there any way to achieve my goal?

Thanks

Avatar
Calli

Community Member, 3 Posts

4 May 2015 at 7:20pm

Nobody got any ideas?

Avatar
Calli

Community Member, 3 Posts

15 May 2015 at 7:58pm

Well for any poor soul trying to find the same answer here: Treat it like a plugin and extend a Controller Class.

_config.php:

Director::addRules(50, array('someLink/$Action' => 'extendedControllerName'));

some File in /code:

class extendedControllerName extends Controller
{
	public static $allowed_actions = array('get');
	
	public function get() { echo "get" }
}

Calling yourURL/someLink/get will then echo "get". If not, flush=1 helps.