【问题标题】:Magento 1.9 core seesion message vanishing on home pageMagento 1.9 核心会话消息在主页上消失
【发布时间】:2022-01-19 09:25:44
【问题描述】:

我正在从控制器向核心会话设置消息并重定向到主页 前 -

$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) } }

谁知道怎么解决这个问题,谢谢

【问题讨论】:

    标签: php session magento magento-1.9


    【解决方案1】:

    //成功消息

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

    //错误信息

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

    //信息消息(见下面的链接)

    Mage::getSingleton('core/session')->addNotice("这只是一个仅供参考 消息...");

    //这些行是让它工作所必需的

    session_write_close(); //这条线非常重要! $this->_redirect('模块/控制器/动作');

    // 或

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

    这将在控制器中工作,但如果您在输出已经发送后尝试重定向,那么您只能通过 javascript 来做到这一点:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2016-11-12
      相关资源
      最近更新 更多