display message

piaoling  2011-07-18 11:01:54

$this->_initLayoutMessages('catalog/session');

$this->_initLayoutMessages('checkout/session');

protected function _initLayoutMessages($messagesStorage)
    {
        if (!is_array($messagesStorage)) {
            $messagesStorage = array($messagesStorage);
        }
        foreach ($messagesStorage as $storageName) {
            $storage = Mage::getSingleton($storageName);
            if ($storage) {
                $block = $this->getLayout()->getMessagesBlock();
                $block->addMessages($storage->getMessages(true));
                $block->setEscapeMessageFlag($storage->getEscapeMessages(true));
            }
            else {
                Mage::throwException(
                     Mage::helper('core')->__('Invalid messages storage "%s" for layout messages initialization', (string) $storageName)
                );
            }
        }
        return $this;
    }

 

 

///////////////////////////////////////////////////////////////////

public function addSuccess($message)
    {
        $this->addMessage(Mage::getSingleton('core/message')->success($message));
        return $this;
    }

public function getLayout()
    {
        return Mage::getSingleton('core/layout');
    }

$block = Mage::getSingleton('core/layout')->getMessagesBlock(); or

$block = $this->getLayout()->getMessagesBlock();

$block->addSuccess('message to addd');

$block->addNotice('message to addd');

$block->addWarning('message to addd');

类别 :  magento(258)  |  浏览(4408)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: