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.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

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

replacement for get_site_mode ?


Go to End


5 Posts   1850 Views

Avatar
Banana

Community Member, 18 Posts

15 November 2010 at 10:11pm

Hello,

since 2.4 DIrector::get_site_mode() is deprecated and throws a user error
( the error message is also misleading, since it is copied from set_site_mode() )

but I can't find a replacement for this function ?

how do I know determine if I'm on site or cms ?

thx,
Banana

Avatar
(deleted)

Community Member, 473 Posts

15 November 2010 at 11:04pm

May I ask why you want to be able to tell the difference between the front and backends? This is usually a sign that controller and model code aren't being kept as separate as they should be.

Though, in response to your question, one way I've been suggesting to people to check, is check if there is a theme set.

Avatar
Banana

Community Member, 18 Posts

15 November 2010 at 11:28pm

the idea is that I "overwrite" the canView function to check a additional custom field.

the model has a new field which stores a date. if this date is older a given date, the page should not be accessable.
But in the cms it should be editable.

I've this from a module, which creates a start and end date for a model. This model used the Director::get_site_mode() to return true if the model is loaded in the cms.

Avatar
Willr

Forum Moderator, 5523 Posts

16 November 2010 at 9:07pm

Might also be able to do your own work around for it

if(Controller::curr() instanceof LeftAndMain) { }

/via Sean

Avatar
Banana

Community Member, 18 Posts

16 November 2010 at 9:33pm

git it working with the SSViewer::current:theme().
it is only set at frontend.

I needed to extend the canView function, otherwise the available check will be done only at the load/init of the page. But the link to this page would be still there.

How it works:

in class Page:
function canView($member=null){
  $ret = parent::canView();
  $theme = SSViewer::current_theme();
  if(!empty($theme)) {
    # do your custom check
    $ret = customCheck();
  }
  return $ret;
}

in controller:
function init(){
  parent:init();
  $check = $this->_customCheck(); # the same as above
  if(empty($check)) {
    # do something
  }
}