【问题标题】:Disable magento cache for page id禁用页面 id 的 magento 缓存
【发布时间】:2014-08-28 11:39:56
【问题描述】:

如何禁用缓存:

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,我可以在每个页面上看到这个块。

【问题讨论】:

  • 你把静态块放在页脚吗?
  • 您是否尝试过从系统缓存管理中禁用块缓存。
  • 不,这个块不在页脚中,如果我禁用块缓存它工作得很好,但问题是页面 id 而不是块还是我错了?

标签: php magento caching


【解决方案1】:

好的,我找到了解决方案:

首先,我将以下内容添加到我的 local.xml:

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

然后我创建了文件:shop-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; ?>

我不知道这是否是解决这个问题的好方法,但它确实有效。所以任何反馈都会很好:)。

【讨论】:

    【解决方案2】:

    编辑“主页”CMS 页面并将其放入“布局更新”字段中。

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

    【讨论】:

    • 这也是可能的,但是我不得不将这么多的 html 推送到 cms 块中
    猜你喜欢
    • 1970-01-01
    • 2017-07-13
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2010-12-10
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多