What does work is:
When I have a cache hit I write in testAction:
$this->_helper->viewRenderer->setNoRender();
and I can do one of the following:
$this->view->placeholder('cache')->set($cachedAction);
$this->_helper->layout()->cache = $cachedAction;
echo $cachedAction;
In the layout script I would then have:
<?= $this->placeholder('cache') ?>
<?= $this->layout()->cache ?>
<?= $this->layout()->content ?>
What does not work is in testAction:
$this->_helper->layout()->content = $cachedAction;
and in layout script:
<?= $this->layout()->content ?>
Why is this so? Is the default name 'content' somehow proteced? Is this reasonable?
I think I'll never completely understand Zend_Layout...
Regards
Viktor
> -----Original Message-----
> From: Viktor Karl Grandgeorg [mailto:info@intelligibel.de]
> Sent: Thursday, April 23, 2009 12:39 PM
> To: fw-mvc@lists.zend.com
> Subject: [fw-mvc] Caching Views
>
> Hello list,
>
> I have ZF MVC with two step view (views and layout). I cache
> the entire already rendered views before they are passed to layout.
> The caching is easy, but I wonder how to replace the view
> with the cached data within the action controller.
> Here is a testAction to illustrate what I mean:
>
> <?php
> class SomeController extends Zend_Controller_Action
> {
> public function testAction()
> {
> $frontendOptions = array(
> 'lifetime' => null,
> 'automatic_serialization' => true
> );
> $backendOptions = array(
> 'cache_dir' => ROOT_PATH . DIRECTORY_SEPARATOR
> . 'cache' . DIRECTORY_SEPARATOR . 'actions'
> );
> $cache = Zend_Cache::factory('Core', 'File',
> $frontendOptions, $backendOptions);
> $cachedAction = $cache->load(
> $this->_request->getActionName());
>
> if (!$cachedAction) {
> $this->view->foo = 'bar';
> $cachedAction = $this->view->render(
> $this->getViewScript());
> $cache->save($cachedAction,
> $this->_request->getActionName());
> } else {
> echo 'from cache:<br />';
> /*
> * Here the view script must not be executed,
> * but the view must be
> * replaced by $cachedAction. It should be placed
> * in layout as
> * $this->layout()->content
> */
> }
> }
> }
>
> The view script simply looks like:
> <p>This is foo: <?= $this->foo ?></p>
>
> Any suggestions?
> best regards
> Viktor
>
没有评论:
发表评论