php – 检测Magento .phtml中的主页,该主页将启用BLOCK_HTML缓存

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 检测Magento .phtml中的主页,该主页将启用BLOCK_HTML缓存脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在cataLOG / navigation / vert_nav.phtML中尝试了以下两种方法添加禁止特定于主页的内容
if($this->getUrl('') == $this->getUrl('*/*/*',array('_current'=>true,'_use_rewrITe'=>true))):

要么

if(
Mage::getSingleton('CMS/page')->getIdentifier() == 'home'  &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' 
) :

两者都工作正常,但是当BLOCK_HTML缓存打开时,它首先工作,然后一段时间后主页开始显示仅用于其他页面内容(在我使用较低的else子句之后).当我关闭BLOCK_HTML时,它的行为与预期的一样.

有趣的是,我在Page / html / head.phtml(对于主页特定的javascript / css)和page / html / header.phtml中使用相同的代码(第一个)(对于应该只出现在页面/ html / header.phtml中的标题横幅)主页),即使BLOCK_HTML为ON,这些工作也很好.

(Magento 1.4.1.1)

以上答案是最佳解决方案.

你可以简单地复制app / code / core / Mage / Catalog / Block / Nagivation.PHP

至:

应用程序/代码/本地/法师/目录/座/ Nagivation.PHP

然后如上所述更改getCacheKeyInfo()方法.

/**
 * Get Key pieces for caching block content
 *
 * @return array
 */
public function getCacheKeyInfo()
{
    $shortCacheid = array(
        'CATALOG_NAVIGATION',Mage::app()->getStore()->getId(),Mage::getDesign()->getPackageName(),Mage::getDesign()->getTheme('template'),Mage::getSingleton('customer/session')->getCustomerGroupId(),'template' => $this->getTemplate(),'name' => $this->getNameInLayout(),$this->getCurrenCategoryKey(),// Your logic to make home/none home have different cache keys
        Mage::getSingleton('cms/page')->getIdentifier() == 'home' ? '1' : '0'
    );
    $cacheId = $shortCacheId;

    $shortCacheId = array_values($shortCacheId);
    $shortCacheId = implode('|',$shortCacheId);
    $shortCacheId = md5($shortCacheId);

    $cacheId['category_path'] = $this->getCurrenCategoryKey();
    $cacheId['short_cache_id'] = $shortCacheId;

    return $cacheId;
}

这将使主页/非主页页面的缓存键不同,这将缓存两个副本,而不是缓存单个模板副本以在所有页面上使用.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 检测Magento .phtml中的主页,该主页将启用BLOCK_HTML缓存全部内容,希望文章能够帮你解决php – 检测Magento .phtml中的主页,该主页将启用BLOCK_HTML缓存所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。