LeftAndMain::$session_namespace

More fine-grained control over session storage,
particularly when reusing the "current page" state.
This commit is contained in:
Ingo Schommer 2012-08-28 00:25:58 +02:00
parent 1e5b04ccad
commit 2f643817a4

View File

@ -98,6 +98,14 @@ class LeftAndMain extends Controller implements PermissionProvider {
*/ */
static $required_permission_codes; static $required_permission_codes;
/**
* @var String Namespace for session info, e.g. current record.
* Defaults to the current class name, but can be amended to share a namespace in case
* controllers are logically bundled together, and mainly separated
* to achieve more flexible templating.
*/
static $session_namespace;
/** /**
* Register additional requirements through the {@link Requirements} class. * Register additional requirements through the {@link Requirements} class.
* Used mainly to work around the missing "lazy loading" functionality * Used mainly to work around the missing "lazy loading" functionality
@ -1252,8 +1260,8 @@ class LeftAndMain extends Controller implements PermissionProvider {
return $this->request->requestVar('ID'); return $this->request->requestVar('ID');
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) { } elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID']; return $this->urlParams['ID'];
} elseif(Session::get("{$this->class}.currentPage")) { } elseif(Session::get($this->sessionNamespace() . ".currentPage")) {
return Session::get("{$this->class}.currentPage"); return Session::get($this->sessionNamespace() . ".currentPage");
} else { } else {
return null; return null;
} }
@ -1268,7 +1276,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
* @param int $id * @param int $id
*/ */
public function setCurrentPageID($id) { public function setCurrentPageID($id) {
Session::set("{$this->class}.currentPage", $id); Session::set($this->sessionNamespace() . ".currentPage", $id);
} }
/** /**
@ -1291,6 +1299,14 @@ class LeftAndMain extends Controller implements PermissionProvider {
return ($record->ID == $this->currentPageID()); return ($record->ID == $this->currentPageID());
} }
/**
* @return String
*/
protected function sessionNamespace() {
$override = $this->stat('session_namespace');
return $override ? $override : $this->class;
}
/** /**
* URL to a previewable record which is shown through this controller. * URL to a previewable record which is shown through this controller.
* The controller might not have any previewable content, in which case * The controller might not have any previewable content, in which case