Fix layout.xml caching causing blocks to render other blocks in Magento

编程入门 行业动态 更新时间:2024-10-10 17:27:38

Fix layout.<a href=https://www.elefans.com/category/jswz/34/1770957.html style=xml caching causing blocks to render other blocks in Magento"/>

Fix layout.xml caching causing blocks to render other blocks in 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:

1 2 3 4 5 6 7 $ 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 ;

更多推荐

Fix layout.xml caching causing blocks to render other blocks in Magento

本文发布于:2024-02-27 09:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1706050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:xml   caching   Fix   layout   render

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!