【发布时间】:2016-09-19 15:37:19
【问题描述】:
我编写了一个 magento 控制器,它在客户会话中存储了一些过滤器信息。
根据 magento 2 文档,我使用依赖注入让 magento 为我生成会话对象:
/**
* @var \Magento\Catalog\Model\Session
*/
protected $_filterSession;
/**
* @param \Magento\Customer\Model\Session $filterSession
*/
public function __construct( \Magento\Customer\Model\Session $filterSession)
{
$this->_filterSession = $filterSession;
}
注入过程运行良好。我能够访问会话,在其中存储一个变量并在进一步调用时返回它。
但magento似乎不时丢弃整个会话信息。我无法准确识别 magento 丢弃信息的那一刻,这似乎有点随机。
代码如下:
$this->_filterSession->setFrequency($frequency);
$frequency = $this->_filterSession->getFrequency();
我尝试了不同的会话范围,但行为是相同的。
经过多次尝试,我尝试使用 PHP-session 来存储信息,但有时甚至这个 session 也被丢弃了。
我不知道我做错了什么,也不知道这种奇怪行为的原因是什么。有没有其他人有类似的问题或想法是什么原因?
提前致谢, 托马斯
【问题讨论】:
标签: php magento session magento2