Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Passing viewVars to cache views, avoiding cake:nocache problems.

  • Loading branch information...
commit a7c7436d8ec758795e0cf38b6062befd12933134 1 parent 7416e58
@jrbasso jrbasso authored
View
2  cake/libs/view/helpers/cache.php
@@ -233,6 +233,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$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 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
$this->{$helper} =& $loadedHelpers[$helper];
}
+ extract($this->viewVars, EXTR_SKIP);
?>';
$content = preg_replace("/(<\\?xml)/", "<?php echo '$1';?>",$content);
$file .= $content;
View
1  cake/libs/view/view.php
@@ -751,6 +751,7 @@ function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = fal
$cache->controllerName = $this->name;
$cache->layout = $this->layout;
$cache->cacheAction = $this->cacheAction;
+ $cache->viewVars = $this->viewVars;
$cache->cache($___viewFn, $out, $cached);
}
}
View
36 cake/tests/cases/libs/view/helpers/cache.test.php
@@ -309,6 +309,42 @@ function testComplexNoCache () {
}
/**
+ * 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
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.