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

Frontend or backend - how found out


Go to End


9 Posts   4681 Views

Avatar
Pike

Community Member, 42 Posts

26 January 2011 at 3:35am

How can I found out programaticaly where am I in frontend or backand?

Avatar
swaiba

Forum Moderator, 1899 Posts

26 January 2011 at 5:06am

hmmmm - how about if your url segment begins "admin"?

Avatar
Pike

Community Member, 42 Posts

26 January 2011 at 5:25am

Edited: 26/01/2011 5:28am

No.
I'm trying:

class StatisticsExtender extends DataObjectDecorator {
function contentControllerInit() {
$cur_url = explode("?",$_SERVER['REQUEST_URI']); // I expecting 'admin'
$params = Director::urlparams();
$controller = Director::urlParam('Controller');
$be = is_subclass_of($controller,"LeftAndMain");
$frontend = ((isset($params['Controller']) && $params['Controller'] == 'RootURLController') || !isset($params['URLSegment']) || (isset($params['URLSegment']) && $params['URLSegment'] != 'sapphire') ? 1 : 0);
$backend = ((isset($params['URLSegment']) && $params['URLSegment'] == 'sapphire') ? 1 : 0);
//...
}
//...
}

No success.

Avatar
swaiba

Forum Moderator, 1899 Posts

26 January 2011 at 5:29am

hmmm well I'd say it would be something in director... Director::get_current_page() and then get the URLsegment from there...

what is it that you are going to use this information for?

Avatar
Pike

Community Member, 42 Posts

26 January 2011 at 5:32am

I'm trying to write statistic module with optional params: use for frontend || use for backend || use for all.

Avatar
swaiba

Forum Moderator, 1899 Posts

26 January 2011 at 5:52am

how about tracking when someone is logged in? non-logged in would mean frontend

any road - I would just track the pages and then worry about how to filter based on "this is an admin url" later. Also I'd ensure the tracking only occurs when (!Director::is_ajax())

Avatar
Pike

Community Member, 42 Posts

26 January 2011 at 5:59am

User can be loged in frontend and backend, right?

You know, in my own CMS I wrote modules, I can read params from xml as it has e.g. Joomla!.
I want the same functionality in SS (e.g. in SS SiteConfig), and I want to know where user sit frontend/backend.
I don't want to use google or piwik (via javascript) nor call from template.

Avatar
swaiba

Forum Moderator, 1899 Posts

26 January 2011 at 6:04am

>> User can be loged in frontend and backend, right?

true, but I am implying that if they are not logged in and it is not ajax it will be a frontend page.

Go to Top