Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

LeftAndMain::$session_namespace

More fine-grained control over session storage,
particularly when reusing the "current page" state.
  • Loading branch information...
commit 2f643817a41d9344b203f29c5545bde639cbf9f7 1 parent 1e5b04c
@chillu chillu authored
Showing with 19 additions and 3 deletions.
  1. +19 −3 admin/code/LeftAndMain.php
View
22 admin/code/LeftAndMain.php
@@ -97,6 +97,14 @@ class LeftAndMain extends Controller implements PermissionProvider {
* See {@link canView()} for more details on permission checks.
*/
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.
@@ -1252,8 +1260,8 @@ public function currentPageID() {
return $this->request->requestVar('ID');
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
- } elseif(Session::get("{$this->class}.currentPage")) {
- return Session::get("{$this->class}.currentPage");
+ } elseif(Session::get($this->sessionNamespace() . ".currentPage")) {
+ return Session::get($this->sessionNamespace() . ".currentPage");
} else {
return null;
}
@@ -1268,7 +1276,7 @@ public function currentPageID() {
* @param int $id
*/
public function setCurrentPageID($id) {
- Session::set("{$this->class}.currentPage", $id);
+ Session::set($this->sessionNamespace() . ".currentPage", $id);
}
/**
@@ -1292,6 +1300,14 @@ public function isCurrentPage(DataObject $record) {
}
/**
+ * @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.
* The controller might not have any previewable content, in which case
* this method returns FALSE.
Please sign in to comment.
Something went wrong with that request. Please try again.