您的位置:首页 > 其它

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:

1234567$layout = $this->getLayout();$update = $layout->getUpdate();$update->load('checkout_onepage_shippingmethod');$layout->generateXml();$layout->generateBlocks();$output = $layout->getOutput();return $output;
To overcome this issue you’ll need to manually set the cache ids at the top of every call to load() like the following:

1

$this->getLayout()->getUpdate()->setCacheId(uniqid("some_custom_cache_id"));

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():

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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: