@@ -58,6 +58,11 @@ class View implements RendererInterface
5858 */
5959 protected $ data = [];
6060
61+ /**
62+ * Merge savedData and userData
63+ */
64+ protected $ tempData = null ;
65+
6166 /**
6267 * The base directory to look in for our Views.
6368 *
@@ -189,11 +194,10 @@ public function render(string $view, array $options = null, bool $saveData = nul
189194 // Store the results here so even if
190195 // multiple views are called in a view, it won't
191196 // clean it unless we mean it to.
192- if ($ saveData ! == null )
197+ if ($ saveData = == null )
193198 {
194- $ this -> saveData = $ saveData ;
199+ $ saveData = $ this -> saveData ;
195200 }
196-
197201 $ fileExt = pathinfo ($ view , PATHINFO_EXTENSION );
198202 $ realPath = empty ($ fileExt ) ? $ view . '.php ' : $ view ; // allow Views as .html, .tpl, etc (from CI3)
199203 $ this ->renderVars ['view ' ] = $ realPath ;
@@ -225,11 +229,17 @@ public function render(string $view, array $options = null, bool $saveData = nul
225229 }
226230
227231 // Make our view data available to the view.
228- extract ($ this ->data );
229232
230- if (! $ this ->saveData )
233+ if (is_null ($ this ->tempData ))
234+ {
235+ $ this ->tempData = $ this ->data ;
236+ }
237+
238+ extract ($ this ->tempData );
239+
240+ if ($ saveData )
231241 {
232- $ this ->data = [] ;
242+ $ this ->data = $ this -> tempData ;
233243 }
234244
235245 ob_start ();
@@ -276,7 +286,7 @@ public function render(string $view, array $options = null, bool $saveData = nul
276286 {
277287 cache ()->save ($ this ->renderVars ['cacheName ' ], $ output , (int ) $ this ->renderVars ['options ' ]['cache ' ]);
278288 }
279-
289+ $ this -> tempData = null ;
280290 return $ output ;
281291 }
282292
@@ -300,16 +310,22 @@ public function render(string $view, array $options = null, bool $saveData = nul
300310 public function renderString (string $ view , array $ options = null , bool $ saveData = null ): string
301311 {
302312 $ start = microtime (true );
313+
303314 if (is_null ($ saveData ))
304315 {
305- $ saveData = $ this ->config -> saveData ;
316+ $ saveData = $ this ->saveData ;
306317 }
307318
308- extract ($ this ->data );
319+ if (is_null ($ this ->tempData ))
320+ {
321+ $ this ->tempData = $ this ->data ;
322+ }
309323
310- if (! $ saveData )
324+ extract ($ this ->tempData );
325+
326+ if ($ saveData )
311327 {
312- $ this ->data = [] ;
328+ $ this ->data = $ this -> tempData ;
313329 }
314330
315331 ob_start ();
@@ -319,7 +335,7 @@ public function renderString(string $view, array $options = null, bool $saveData
319335 @ob_end_clean ();
320336
321337 $ this ->logPerformance ($ start , microtime (true ), $ this ->excerpt ($ view ));
322-
338+ $ this -> tempData = null ;
323339 return $ output ;
324340 }
325341
@@ -354,8 +370,8 @@ public function setData(array $data = [], string $context = null): RendererInter
354370 {
355371 $ data = \esc ($ data , $ context );
356372 }
357-
358- $ this ->data = array_merge ($ this ->data , $ data );
373+ $ this -> tempData = $ this -> tempData ?? $ this -> data ;
374+ $ this ->tempData = array_merge ($ this ->tempData , $ data );
359375
360376 return $ this ;
361377 }
@@ -379,7 +395,8 @@ public function setVar(string $name, $value = null, string $context = null): Ren
379395 $ value = \esc ($ value , $ context );
380396 }
381397
382- $ this ->data [$ name ] = $ value ;
398+ $ this ->tempData = $ this ->tempData ?? $ this ->data ;
399+ $ this ->tempData [$ name ] = $ value ;
383400
384401 return $ this ;
385402 }
@@ -407,7 +424,7 @@ public function resetData(): RendererInterface
407424 */
408425 public function getData (): array
409426 {
410- return $ this ->data ;
427+ return $ this ->tempData ?? $ this -> data ;
411428 }
412429
413430 //--------------------------------------------------------------------
0 commit comments