【问题标题】:Session Variable outside magentomagento 之外的会话变量
【发布时间】:2015-04-03 17:38:18
【问题描述】:

我必须在 magento 之外的文件中读取$_SESSION['name'],或者更好的是在 /magento/folder 中。 我尝试了任何解决方案都没有好的结果。

例子

Mage::getSingleton('core/session')->setUName($_SESSION['username']);

在外部文件中使用此代码:

require_once("../app/Mage.php");
umask(0);
Mage::app();

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::init();

$_SESSION['username'] = Mage::getSingleton('core/session')->getUName();

结果???变量为空......

我对 magento 很着迷……我需要这个变量!!!!

如果有人可以帮助我,我会说声谢谢。

【问题讨论】:

标签: php magento variables session magento-1.9


【解决方案1】:

快速解决方案:

Mage::getSingleton('core/session', array('name' => 'frontend'))->getUName();

解释:

会话从这里开始:Mage_Core_Model_Session_Abstract_Varien::start()

当默认 magento 尝试启动会话时,它使用参数运行:$sessionName = 'frontend'。当你运行 Mage::getSingleton('core/session') - 你实例化没有任何参数的会话。而且您没有拉动必要的会话。这样是因为您需要再添加一个带有会话名称的参数

【讨论】:

  • thks ......你救了我的命......对不起,但我不能为你的声誉 +1,因为我的声誉很低......
  • 嗨@zhartaunik:你知道我们如何用“客户/会话”获得同样的东西吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多