0

How do I reset a setData variable within a view?

Example: view.phtml:

$this->getChild('additional')->setData('foo', 'Bar'); 


if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
    <?php foreach ($detailedInfoGroup as $alias => $html):?>
       <?php echo $html ?>
    <?php endforeach;?>
<?php endif;

attributes.phtml

echo $this->getData('foo'); // returns: Bar

When I am trying to set the data again but with another value (within view.phtml) like:

view.phtml:

$this->getChild('additional')->setData('foo', 'Second'); 


if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
    <?php foreach ($detailedInfoGroup as $alias => $html):?>
       <?php echo $html ?>
    <?php endforeach;?>
<?php endif;

attributes.phtml

echo $this->getData('foo'); // it still returns: Bar

How do I update this variable foo?

Thanks,

Martijn

4

1 回答 1

0

您很好地重置了变量,但您必须禁用块的缓存。

删除缓存块的 _construct 函数的缓存信息。由此:

protected function _construct()
{
$this->addData(array(
‘cache_lifetime’=> false,
‘cache_tags’ => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG)
));
}

对此:

protected function _construct() {}
于 2013-11-20T15:33:55.747 回答