2014-08-28 60 views
0

我如何禁用缓存:禁用的Magento缓存

Mage::getSingleton('cms/page')->getIdentifier() 

我需要禁用缓存,因为我只希望在“家”这个页面显示静态块:

<?php if (Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): ?> 
<div> 
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-long')->toHtml() ?> 
</div> 
<?php endif; ?> 

目前magento缓存此页面的id,我可以在每一页上看到这个块。

+0

你把静态块放在页脚? – 2014-08-28 11:41:20

+0

您是否尝试过禁止系统缓存管理中的块缓存? – anwerj 2014-08-28 11:41:42

+0

检查这个http://magento.stackexchange.com/questions/3124/how-can-i-disable-cache-for-particular-section-or-block – 2014-08-28 11:43:40

回答

0

好,我找到了一个解决方案:

首先,我增加了以下我local.xml中:

<reference name="midcolumn"> 
    <block type="core/template" template="page/html/shop-description.phtml"> 
     <action method="setCacheLifetime"><s>null</s></action> 
    </block> 
</reference> 

然后,我创建的文件:店description.phtml具有以下内容:

<?php if (Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): ?> 
<section class="f-fix"> 
    <div class="container"> 
     <div class="headingBox"><h2><span>About the shop</span></h2></div> 
     <div class="shop-description-long"> 
     <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-long')->toHtml() ?> 
     </div> 
     <div class="shop-description-image"> 
     <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-image')->toHtml() ?> 
     </div> 
    </div> 
</section> 
<?php endif; ?> 

我不知道这是否是一个很好的解决方案,但它的工作原理。所以任何反馈都会很好:)。

0

编辑“家庭”CMS页面,并将其置于“布局更新”字段中。

<reference name="content"> 
    <block type="cms/block" name="shop_description_long"> 
     <action method="setBlockId"><id>shop-description-long</id></action> 
    </block> 
</reference> 
+0

这也是可能的,但所以我不得不把这么多的HTML到cms块 – Fox 2014-08-29 13:38:03