Fix layout.xml caching causing blocks to render other blocks in Magento
2015-10-23 13:40
351 查看
http://davemacaulay.com/fix-layout-xml-caching-causing-blocks-render-blocks-magento/
缓存开启后 在付款页面 点击 next无法继续
If you’re building a system which uses Ajax and makes numerous calls to $this->getLayout()->getUpdate()->load() (which
enables you to load sections of the layout.xml file) and render these all on the same page you’ll come across an error where the blocks all render as the first block in the call. This is due to the way the cache id’s work against these blocks.
You can see this functionality used within the checkout such as in the _getShippingMethodsHtml() withinOnepageController.php function:
To overcome this issue you’ll need to manually set the cache ids at the top of every call to load() like the following:
This will make sure the layout caching knows that this block is different from any others called on the same page.
So for instance in the code example above you could change the function code to read the following and avoid any caching issues. You’ll need to add custom cache ids into all calls to $this->getLayout()->getUpdate()->load():
缓存开启后 在付款页面 点击 next无法继续
If you’re building a system which uses Ajax and makes numerous calls to $this->getLayout()->getUpdate()->load() (which
enables you to load sections of the layout.xml file) and render these all on the same page you’ll come across an error where the blocks all render as the first block in the call. This is due to the way the cache id’s work against these blocks.
You can see this functionality used within the checkout such as in the _getShippingMethodsHtml() withinOnepageController.php function:
1234567 | $layout = $this->getLayout();$update = $layout->getUpdate();$update->load('checkout_onepage_shippingmethod');$layout->generateXml();$layout->generateBlocks();$output = $layout->getOutput();return $output; |
1 | $this->getLayout()->getUpdate()->setCacheId(uniqid("some_custom_cache_id")); |
So for instance in the code example above you could change the function code to read the following and avoid any caching issues. You’ll need to add custom cache ids into all calls to $this->getLayout()->getUpdate()->load():
1 2 3 4 5 6 7 8 | $layout=$this->getLayout(); $update=$layout->getUpdate(); $update->setCacheId(uniqid("custom_checkout_onepage_shippingmethod")); $update->load('checkout_onepage_shippingmethod'); $layout->generateXml(); $layout->generateBlocks(); $output=$layout->getOutput(); return$output; |
相关文章推荐
- Appium 服务关键字
- HTML5(javascript) Audio/video标签属性常用方法
- 关于旋转后缩放产生的问题解决方案
- 《数据分析的统计基础》学习笔记(二) 描述性统计分析
- Object-C与Swift的混合编程
- POJ 2391 最大流 二分 拆点 floyd
- 运行Hadoop伪分布式实例
- 高效分布式数据库缓存经典解决方案
- Java快速从一个文件夹复制到另外一个文件夹
- 自定义标签 titlebar
- Effective Java Chapter 1
- sqlite docs
- Jmeter关联
- php生成代金券码
- 高版本的JavaCV是可以调用低版本的openCV的
- wireshark添加tcp.stream列
- 开源项目:底部动作条(BottomSheet)
- 取得手机SDcard的大小和可用空间
- Xcode上传App到Appstore,报错Error ITMS-90049:"This bundle is invalid.The bundle..
- PHP 教程