magento Messages and Global Messages Blocks

Both use the same block, as we can see in page.xml:

<block type="core/messages" name="global_messages" as="global_messages"/> 
<block type="core/messages" name="messages" as="messages"/>

When you add a message, you add it to the session, rather than to either of the
messages blocks, so the code below causes the Mage_Customer_Model_Session object
to have an error logged to it:

Mage::getSingleton('customer/session')->addError('Please enter all required information');

At this point neither message blocks know anything about the message, this is
where the difference between the global messages and the messages block comes
in - it’s purely down to what gets inserted into the relevant message block.

For the global messages block, I’m not sure how it gets filled actually, I can’t
find any reference in the code at all to something interacting with the block.

For the messages block, it gets filled by you using _initLayoutMessages() from
your controller, like so:

$this->_initLayoutMessages('customer/sesssion');

What this does is basically the following, which is a simplification from
Mage_Core_Controller_Varien_Action::_initLayoutMessages():

$storage = Mage::getSingleton('customer/sesssion'); 
$block = $this->getLayout()->getMessagesBlock(); 
$block->addMessages($storage->getMessages(true));

A side note - the Magento templates use this method call to render the message
block:

$this->getMessagesBlock()->getGroupedHtml();

This stops the Enterprise Full Page Cache from working, instead this should be
used:

$this->getMessagesBlock()->toHtml();

In summary - it looks like the global messages block is not used at all. If
anyone knows any better, let me know!

转载于:https://my.oschina.net/liufeng815/blog/402890

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值