Jump to:

23006 Posts in 11856 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Frontend or backend - how found out

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

Page: 1 2
Go to End
Author Topic: 1467 Views
  • Pike
    Avatar
    Community Member
    40 Posts

    Frontend or backend - how found out Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Frontend or backend - how found out Link to this post

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

  • Pike
    Avatar
    Community Member
    40 Posts

    Re: Frontend or backend - how found out Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Frontend or backend - how found out Link to this post

    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?

  • Pike
    Avatar
    Community Member
    40 Posts

    Re: Frontend or backend - how found out Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Frontend or backend - how found out Link to this post

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

  • Pike
    Avatar
    Community Member
    40 Posts

    Re: Frontend or backend - how found out Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Frontend or backend - how found out Link to this post

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

    1467 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.