簡體   English   中英

Magento 1.9 core seesion 消息在主頁上消失

[英]Magento 1.9 core seesion message vanishing on home page

我正在從 controller 向核心 session 設置消息並重定向到主頁 Ex -

$session = Mage::getSingleton('core/session');
$session->addError('This is test message');
$this->_redirect('/');

但它沒有顯示在主頁上,我也檢查了 xml 文件和其他塊,但找不到任何線索。 當我在主頁 phtml 文件上調試消息時,它顯示如下

 $messages=Mage::getSingleton("core/session")->getMessages();
    var_dump($messages);

object(Mage_Core_Model_Message_Collection)#77 (2) { 
["_messages":protected]=> array(0) { } ["_lastAddedMessage":protected]=> object(Mage_Core_Model_Message_Error)#76 (6) { 
["_type":protected]=> string(5) "error" ["_code":protected]=> string(34) "This is test message" ["_class":protected]=> string(0) "" ["_method":protected]=> string(0) "" 
["_identifier":protected]=> NULL ["_isSticky":protected]=> bool(false) } }

有誰知道怎么解決這個問題,謝謝

//一條成功消息

Mage::getSingleton('core/session')->addSuccess("一些成功信息");

//一個錯誤信息

Mage::getSingleton('core/session')->addError("一些錯誤信息");

//一條信息消息(見下面的鏈接)

Mage::getSingleton('core/session')->addNotice("這只是一條僅供參考的消息...");

//這些行是讓它工作所必需的

session_write_close(); //這一行非常重要; $this->_redirect('模塊/控制器/動作');

// 或者

$url = '路徑/到/你的/頁面'; $this->_redirectUrl($url);

這將在 controller 中工作,但是如果您在 output 已經發送之后嘗試重定向,那么您只能通過 javascript 執行此操作:

<script language=”javascript” type=”text/javascript”>
window.location.href=”module/controller/action/getparam1/value1/etc"";
</script> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM