mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Passing viewVars to cache views, avoiding cake:nocache problems.
This commit is contained in:
parent
7416e58759
commit
a7c7436d8e
3 changed files with 39 additions and 0 deletions
|
@ -233,6 +233,7 @@ class CacheHelper extends AppHelper {
|
|||
$controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
|
||||
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
|
||||
$controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
|
||||
$controller->viewVars = $this->viewVars = unserialize(stripslashes(\'' . addslashes(serialize($this->viewVars)) . '\'));
|
||||
$controller->theme = $this->theme = \'' . $this->theme . '\';
|
||||
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
|
||||
|
||||
|
@ -253,6 +254,7 @@ class CacheHelper extends AppHelper {
|
|||
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
|
||||
$this->{$helper} =& $loadedHelpers[$helper];
|
||||
}
|
||||
extract($this->viewVars, EXTR_SKIP);
|
||||
?>';
|
||||
$content = preg_replace("/(<\\?xml)/", "<?php echo '$1';?>",$content);
|
||||
$file .= $content;
|
||||
|
|
|
@ -751,6 +751,7 @@ class View extends Object {
|
|||
$cache->controllerName = $this->name;
|
||||
$cache->layout = $this->layout;
|
||||
$cache->cacheAction = $this->cacheAction;
|
||||
$cache->viewVars = $this->viewVars;
|
||||
$cache->cache($___viewFn, $out, $cached);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,6 +308,42 @@ class CacheHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* test cache of view vars
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testCacheViewVars() {
|
||||
$this->Controller->cache_parsing();
|
||||
$this->Controller->params = array(
|
||||
'controller' => 'cache_test',
|
||||
'action' => 'cache_parsing',
|
||||
'url' => array(),
|
||||
'pass' => array(),
|
||||
'named' => array()
|
||||
);
|
||||
$this->Controller->cacheAction = 21600;
|
||||
$this->Controller->here = '/cacheTest/cache_parsing';
|
||||
$this->Controller->action = 'cache_parsing';
|
||||
|
||||
$View = new View($this->Controller);
|
||||
$result = $View->render('index');
|
||||
$this->assertNoPattern('/cake:nocache/', $result);
|
||||
$this->assertNoPattern('/php echo/', $result);
|
||||
|
||||
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
||||
$this->assertTrue(file_exists($filename));
|
||||
|
||||
$contents = file_get_contents($filename);
|
||||
$this->assertPattern('/\$this\-\>viewVars.*variable/', $contents);
|
||||
$this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents);
|
||||
$this->assertPattern('/php echo \$variable/', $contents);
|
||||
$this->assertPattern('/variableValue/', $contents);
|
||||
|
||||
@unlink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* test cacheAction set to a boolean
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue