2012-05-29 75 views
3

我在頁腳中包含名爲track your order的鏈接。如果用戶在未登錄的情況下單擊此鏈接,則應顯示錯誤消息,如please login to track your order如何在magento中添加自定義錯誤消息

我是新來的magento請指導我這樣做。

+0

爲什麼你要顯示此鏈接擺在首位用戶「未登錄」? – sulabh

回答

0

您可以使用addError()功能,包括在會話的錯誤信息

2

把這個代碼在你的控制器

$session = Mage::getSingleton('customer/session'); 
if (!$session->getCustomerId()) { 
    Mage::getSingleton('customer/session')->addError('You are not logged in'); 
} 
8

因爲此問題出現在Google中而被添加。

對於一個黃色的「警告」消息(你可能要爲此目的之一),使用

Mage::getSingleton('core/session')->addNotice('Please log in to track your order'); 

對於綠色「成功」的消息,使用

Mage::getSingleton('core/session')->addSuccess('Tracking successful'); 

對於紅「錯誤」的信息,使用

Mage::getSingleton('core/session')->addError('There was an error tracking your parcel'); 
2
  1. 設置您的消息。
Mage::getSingleton("core/session")->addSuccess("Add success message"); 
Mage::getSingleton("core/session")->addError("Please login"); 
Mage::getSingleton("core/session")->addNotice("Add notification message"); 
  • 顯示你在頁腳信息。
  • <?php echo $this->getChildHtml('global_messages'); ?> 
    

    3.Define區塊佈局。 (可選如果使用自定義的擴展名或沒有定義)

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

    +0

    完美答案!!! –

    相關問題