2014-08-28 56 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