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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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


Community Member, 18 Posts

15 November 2010 at 10:11pm


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 ?



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.


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.


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


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(){
  $check = $this->_customCheck(); # the same as above
  if(empty($check)) {
    # do something