@@ -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 (is_null ( $ saveData) )
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 ) )
231234 {
232- $ this ->data = [];
235+ $ this ->tempData = $ this ->data ;
236+ }
237+
238+ extract ($ this ->tempData );
239+
240+ if ($ saveData )
241+ {
242+ $ this ->data = $ this ->tempData ;
233243 }
234244
235245 ob_start ();
@@ -277,6 +287,8 @@ public function render(string $view, array $options = null, bool $saveData = nul
277287 cache ()->save ($ this ->renderVars ['cacheName ' ], $ output , (int ) $ this ->renderVars ['options ' ]['cache ' ]);
278288 }
279289
290+ $ this ->tempData = null ;
291+
280292 return $ output ;
281293 }
282294
@@ -300,16 +312,22 @@ public function render(string $view, array $options = null, bool $saveData = nul
300312 public function renderString (string $ view , array $ options = null , bool $ saveData = null ): string
301313 {
302314 $ start = microtime (true );
315+
303316 if (is_null ($ saveData ))
304317 {
305- $ saveData = $ this ->config -> saveData ;
318+ $ saveData = $ this ->saveData ;
306319 }
307320
308- extract ($ this ->data );
321+ if (is_null ($ this ->tempData ))
322+ {
323+ $ this ->tempData = $ this ->data ;
324+ }
325+
326+ extract ($ this ->tempData );
309327
310- if (! $ saveData )
328+ if ($ saveData )
311329 {
312- $ this ->data = [] ;
330+ $ this ->data = $ this -> tempData ;
313331 }
314332
315333 ob_start ();
@@ -320,6 +338,8 @@ public function renderString(string $view, array $options = null, bool $saveData
320338
321339 $ this ->logPerformance ($ start , microtime (true ), $ this ->excerpt ($ view ));
322340
341+ $ this ->tempData = null ;
342+
323343 return $ output ;
324344 }
325345
@@ -355,7 +375,8 @@ public function setData(array $data = [], string $context = null): RendererInter
355375 $ data = \esc ($ data , $ context );
356376 }
357377
358- $ this ->data = array_merge ($ this ->data , $ data );
378+ $ this ->tempData = $ this ->tempData ?? $ this ->data ;
379+ $ this ->tempData = array_merge ($ this ->tempData , $ data );
359380
360381 return $ this ;
361382 }
@@ -379,7 +400,8 @@ public function setVar(string $name, $value = null, string $context = null): Ren
379400 $ value = \esc ($ value , $ context );
380401 }
381402
382- $ this ->data [$ name ] = $ value ;
403+ $ this ->tempData = $ this ->tempData ?? $ this ->data ;
404+ $ this ->tempData [$ name ] = $ value ;
383405
384406 return $ this ;
385407 }
@@ -407,7 +429,7 @@ public function resetData(): RendererInterface
407429 */
408430 public function getData (): array
409431 {
410- return $ this ->data ;
432+ return is_null ( $ this ->tempData ) ? $ this -> data : $ this -> tempData ;
411433 }
412434
413435 //--------------------------------------------------------------------
0 commit comments