如何在 Magento 的我自己的会话变量中保存值? [英] How do I save value in my own session variable in Magento?
本文介绍了如何在 Magento 的我自己的会话变量中保存值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Magento 并尝试在其 index.php 文件中按如下方式在会话中保存一个值,但该值没有被保留.
I am using Magento and trying to save a value in the session as follows in its index.php file, but the value is not being retained.
$_SESSION['myvar'] = '1';
我该怎么做?
谢谢
推荐答案
假设您想将值Hello world"保存到会话中的欢迎消息"变量中.代码将是:
Let's say you want to save the value "Hello world" to the "welcome message" variable in the session. The code would be :
$inputMessage = 'Hello World';
Mage::getSingleton('core/session')->setWelcomeMessage($inputMessage);
现在您想在代码/站点的其他地方回显欢迎消息".
Now you want to echo the "welcome message" somewhere else in your code/site.
$outputMessage = Mage::getSingleton('core/session')->getWelcomeMessage();
echo $this->__($outputMessage);
这篇关于如何在 Magento 的我自己的会话变量中保存值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文