Skip to content
This repository
Browse code

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
Ingo Schommer authored August 28, 2012

Showing 1 changed file with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. 22  admin/code/LeftAndMain.php
22  admin/code/LeftAndMain.php
@@ -97,6 +97,14 @@ class LeftAndMain extends Controller implements PermissionProvider {
97 97
 	 * See {@link canView()} for more details on permission checks.
98 98
 	 */
99 99
 	static $required_permission_codes;
  100
+
  101
+	/**
  102
+	 * @var String Namespace for session info, e.g. current record.
  103
+	 * Defaults to the current class name, but can be amended to share a namespace in case
  104
+	 * controllers are logically bundled together, and mainly separated
  105
+	 * to achieve more flexible templating.
  106
+	 */
  107
+	static $session_namespace;
100 108
 	
101 109
 	/**
102 110
 	 * Register additional requirements through the {@link Requirements} class.
@@ -1252,8 +1260,8 @@ public function currentPageID() {
1252 1260
 			return $this->request->requestVar('ID');
1253 1261
 		} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
1254 1262
 			return $this->urlParams['ID'];
1255  
-		} elseif(Session::get("{$this->class}.currentPage")) {
1256  
-			return Session::get("{$this->class}.currentPage");
  1263
+		} elseif(Session::get($this->sessionNamespace() . ".currentPage")) {
  1264
+			return Session::get($this->sessionNamespace() . ".currentPage");
1257 1265
 		} else {
1258 1266
 			return null;
1259 1267
 		}
@@ -1268,7 +1276,7 @@ public function currentPageID() {
1268 1276
 	 * @param int $id
1269 1277
 	 */
1270 1278
 	public function setCurrentPageID($id) {
1271  
-		Session::set("{$this->class}.currentPage", $id);
  1279
+		Session::set($this->sessionNamespace() . ".currentPage", $id);
1272 1280
 	}
1273 1281
 
1274 1282
 	/**
@@ -1292,6 +1300,14 @@ public function isCurrentPage(DataObject $record) {
1292 1300
 	}
1293 1301
 	
1294 1302
 	/**
  1303
+	 * @return String
  1304
+	 */
  1305
+	protected function sessionNamespace() {
  1306
+		$override = $this->stat('session_namespace');
  1307
+		return $override ? $override : $this->class;
  1308
+	}
  1309
+
  1310
+	/**
1295 1311
 	 * URL to a previewable record which is shown through this controller.
1296 1312
 	 * The controller might not have any previewable content, in which case 
1297 1313
 	 * this method returns FALSE.

0 notes on commit 2f64381

Please sign in to comment.
Something went wrong with that request. Please try again.