mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
ENHANCEMENT Allowing to simulate subsite access through URL parameter ?SubsiteID=<ID> (doesn't set session, so only works for current page)
This commit is contained in:
parent
2d4a999bfc
commit
32b1542a4b
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* A dynamically created subdomain. SiteTree objects can now belong to a subdomain
|
||||
* A dynamically created subdomain. SiteTree objects can now belong to a subdomain.
|
||||
* You can simulate subsite access without creating subdomains by appending ?SubsiteID=<ID> to the request.
|
||||
*
|
||||
* @package subsites
|
||||
*/
|
||||
@ -231,13 +232,24 @@ JS;
|
||||
* directly from ModelAsController::getNestedController. Only gets Subsite instances which have their
|
||||
* {@link IsPublic} flag set to TRUE.
|
||||
*
|
||||
* You can simulate subsite access without creating subdomains by appending ?SubsiteID=<ID> to the request.
|
||||
*
|
||||
* @todo Pass $request object from controller so we don't have to rely on $_REQUEST
|
||||
*
|
||||
* @param boolean $cache
|
||||
* @return int ID of the current subsite instance
|
||||
*/
|
||||
static function currentSubsiteID($cache = true) {
|
||||
$id = Session::get('SubsiteID');
|
||||
if(isset($_REQUEST['SubsiteID'])) {
|
||||
$id = (int)$_REQUEST['SubsiteID'];
|
||||
} else if(Session::get('SubsiteID')) {
|
||||
$id = Session::get('SubsiteID');
|
||||
}
|
||||
|
||||
if($id === null) Session::set('SubsiteID', $id = self::getSubsiteIDForDomain($cache));
|
||||
if(!isset($id) || $id === NULL) {
|
||||
$id = self::getSubsiteIDForDomain($cache);
|
||||
Session::set('SubsiteID', $id);
|
||||
}
|
||||
|
||||
return (int)$id;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user