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.

Upgrading SilverStripe

Ask questions about upgrading SilverStripe to the latest version.

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

replacement for get_site_mode ?


Reply

5 Posts   1129 Views

Avatar
Banana

15 November 2010 at 10:11pm Community Member, 18 Posts

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
simon_w

15 November 2010 at 11:04pm Forum Moderator, 474 Posts

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

15 November 2010 at 11:28pm Community Member, 18 Posts

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

16 November 2010 at 9:07pm Forum Moderator, 5511 Posts

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

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

/via Sean

Avatar
Banana

16 November 2010 at 9:33pm Community Member, 18 Posts

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