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

Frontend or backend - how found out


Go to End
Reply

9 Posts   1668 Views

Avatar
Pike

26 January 2011 at 3:35am Community Member, 40 Posts

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

Avatar
swaiba

26 January 2011 at 5:06am Forum Moderator, 1796 Posts

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

Avatar
Pike

26 January 2011 at 5:25am (Last edited: 26 January 2011 5:28am), Community Member, 40 Posts

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

26 January 2011 at 5:29am Forum Moderator, 1796 Posts

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

26 January 2011 at 5:32am Community Member, 40 Posts

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

Avatar
swaiba

26 January 2011 at 5:52am Forum Moderator, 1796 Posts

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

26 January 2011 at 5:59am Community Member, 40 Posts

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

26 January 2011 at 6:04am Forum Moderator, 1796 Posts

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