Magento 消息提示

Magento 消息提示

//成功

Mage::getSingleton('customer/session')->addSuccess('恭喜您关联会员卡成功!');

//失败

Mage::getSingleton('customer/session')->addError($e->getMessage());

错误处理

if($this->getRequest()->isPost()){

    try {

$methodList = Mage::helper('recharge')->getRechargeMethodList();

$method = $this->getRequest()->getPost('method','');

$points = floatval($this->getRequest()->getPost('points',0));

if($points <= 0){

throw new exception('充值金额不能小于等于0');  //1错误异常

}

if('' == $method || !array_key_exists($method,$methodList)){

throw new exception('充值方式选择错误');

}

$methodInstance = Mage::helper('recharge')->getMethodInstance($method);

if (!$methodInstance) {

throw new exception('初始化充值错误');

}

Mage::getSingleton('customer/session')->addSuccess('恭喜您关联会员卡成功!');

    }catch (exception $e){

Mage::getSingleton('customer/session')->addError($e->getMessage());//2添加错误

    }

}

$this->loadLayout();

$this->_initLayoutMessages('customer/session'); //3.回显错误

$this->renderLayout();

phtml中添加

<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>

原文:http://www.myexception.cn/program/728671.html

--------------------------------------------------

magento 成功 错误 警告 提示的使用方法

控制器里面添加下面代码 加页面提示

Mage::getSingleton('customer/session')->addSuccess($this->__('This email does not require confirmation.'));

这个是绿色的提示

Mage::getSingleton('customer/session')->addError($this->__('Login and password are required.'));

这个是红色的提示

Mage::getSingleton('customer/session')->addNotice($this->__('Please specify product option(s).'));

这个是黄色的提示


phtml里面必须添加下面代码 才可以show页面提示
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php echo $this->getMessagesBlock()->toHtml() ?>


控制器里面必须添加下面代码
$this->_initLayoutMessages('customer/session');

使用其他session ,如 check/session 等,请参考上面方式 举一反三

原文:http://bugmaycry.blog.163.com/blog/static/185272293201151553535674/

博主注:更详细的图文并茂版请参考 https://segmentfault.com/a/1190000004540153

 

posted @ 2017-01-13 11:10  ec04  阅读(411)  评论(0编辑  收藏  举报