summaryrefslogtreecommitdiffstats
path: root/system/core/Loader.php
diff options
context:
space:
mode:
authorChristian Mohr <christian.mohr@insitu.de>2018-01-03 16:37:55 +0100
committerChristian Mohr <christian.mohr@insitu.de>2018-01-03 16:37:55 +0100
commit7d591a3c36cd58b430125eee214a9dba36290d00 (patch)
treec5ecd7f4810d2658bc37160044ebdd60ca925ee5 /system/core/Loader.php
parenta0b016905a3540c05be5d0c480ca83cdd58ad850 (diff)
reproduce caching behaviour for nested view() calls
Signed-off-by: Christian Mohr <christian.mohr@insitu.de>
Diffstat (limited to 'system/core/Loader.php')
-rw-r--r--system/core/Loader.php34
1 files changed, 30 insertions, 4 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 98db8d4f7..1e5eeecd5 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -94,6 +94,13 @@ class CI_Loader {
protected $_ci_cached_vars = array();
/**
+ * stack of variables for nested _ci_load calls
+ *
+ * @var array
+ */
+ protected $_ci_vars_stack = array();
+
+ /**
* List of loaded classes
*
* @var array
@@ -934,14 +941,30 @@ class CI_Loader {
}
/*
- * Extract and cache variables
+ * Extract and stack variables
*
* You can either set variables using the dedicated $this->load->vars()
* function or via the second parameter of this function. We'll merge
- * the two types.
+ * the two types. Additionally we merge them with the last variables
+ * from the nested call stack so that views that are embedded within
+ * other views can have access to these variables.
*/
- empty($this->_ci_cached_vars) OR $_ci_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
- extract($_ci_vars);
+
+ // merge with global cached vars (first call) or last state from nested
+ // call stack (subsequent nested calls)
+ // if (!empty($this->_ci_vars_stack)) {
+ // $_ci_vars = array_merge(end($this->_ci_vars_stack), $_ci_vars);
+ // } else if (!empty($this->_ci_cached_vars)) {
+ // // merge with cached vars
+ // $_ci_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
+ // }
+
+ empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
+
+
+ // push current _ci_vars state to stack and extract it
+ // array_push($this->_ci_vars_stack, $_ci_vars);
+ extract($this->_ci_cached_vars);
/**
* Buffer the output
@@ -959,6 +982,9 @@ class CI_Loader {
include($_ci_path); // include() vs include_once() allows for multiple views with the same name
log_message('info', 'File loaded: '.$_ci_path);
+ // remove current _ci_vars state from stack
+ // array_pop($this->_ci_vars_stack);
+
// Return the file data if requested
if ($_ci_return === TRUE)
{