2014-12-04 52 views
0

我的magento中的知識並不深,所以我在magento全局消息輸出中遇到了麻煩。Magento中的全局消息出現的問題

我創建了我的模塊。在我的模塊的索引頁面(路線是/優惠券)我有一個表格。因此,通過文章中,我將數據發送到控制器(路線是一樣的(/ voucehrs))其中I驗證數據:

if(!isset($post["to_name"]) || !$post['to_name']) 
    { 
     Mage::getSingleton('customer/session')->addError($this->__('Please enter "To Name" information')); 
     $errors = 1; 
    } 

... 

    if(!$errors) 
    { 
     Mage::getSingleton('customer/session')->addSuccess($this->__('Your order is successfully saved and now is in process')); 
    } 

在我使用<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>但沒有任何反應的模板,雖然我甩會話變量在那裏我可以看到成功的消息。

我哪裏錯了?

回答

0

您可以試試core/session而不是customer/session?它可能會幫助你。

0

首先,我們強烈建議您安裝/配置Xdebug - 此工具將爲您節省大量時間。

對於這個問題,嘗試使用

Mage::getSingleton('customer/session') 

代替

Mage::getSingleton('core/session') 

如果它不工作,你可以嘗試:

// after post form 
$this->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton(‘customer/session’)->getMessages(true)); 

// when display 
$this->getLayout()->getMessagesBlock()->getGroupedHtml(); 

希望這將有助於。 :)

3

請檢查您的控制器。如果您呈現佈局,則必須在您的操作中包含以下代碼。

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

所以,你的行動應該是這樣的:

$this->loadLayout(); 
$this->_initLayoutMessages('customer/session'); 
$this->renderLayout(); 

它可以幫助你。

2
Notice 
Mage::getSingleton('core/session')->addNotice('Notice message'); 

enter image description here

Success 
Mage::getSingleton('core/session')->addSuccess('Success message'); 

enter image description here

Error 
Mage::getSingleton('core/session')->addError('Error message'); 

enter image description here

Warning (admin only) 
Mage::getSingleton('adminhtml/session')->addWarning('Warning message'); 

enter image description here

從控制器

輸出錯誤

public function sendAction() 
    { 
     try 
     { 
      $mail = new Zend_Mail(); 
      $mail->send(); 
     } 
     catch (Exception $e) 
     { 
      Mage::getSingleton('core/session')->addError('Error sending mail'); 
     } 
     $this->loadLayout(); 
     $this->renderLayout(); 
    } 

MOre info for session in mageno how to get and set

0

我發現這個堆棧溢出後極有幫助。

對我而言有效的是Alex Ivanov和Emipro Technologies Pvt。的組合。公司的answsers,如下(控制器代碼):

$this->loadLayout(); 
$this->_initLayoutMessages('core/session'); 
$this->renderLayout();