Opencart 中的会话变量
有人可以解释会话变量保存在哪里吗?
我在控制器的 header.php 中添加了一些会话变量,例如:
$this->session->data['day']=date("d",strtotime($row['startdate']));
这在加载网站时有效,当我单击产品时,所有变量都消失了,除了 [语言]
、[currency]
和 [cart]
由 Opencart 设置。
我猜还有另一个文件或控制器文件,我在其中设置变量,或者 [language]
、[currency]
和 [cart]
所在位置设置但我找不到它。
提前致谢。
Can someone explain where session variables are held?
I have added some session variables in header.php in the controller, for example:
$this->session->data['day']=date("d",strtotime($row['startdate']));
This works when loading the site, and when I click on a product, all the variables are gone, except for the [language]
, [currency]
and [cart]
which are set by Opencart.
I guess there is another file or controller file where I set the variables, or where [language]
, [currency]
and [cart]
are set but I cannot find it.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
会话值未在文件中设置。如果要设置会话变量,请使用
和 检索刚刚访问的值
例如,要回显它,请使用
Session values are not set in a file. If you want to set a session variable, use
and to retrieve the value you just access
For example, to echo it use
在这里,我将变量保存到会话中:
现在在
catalog/controller/checkout/guest.php
的index
方法中检查该会话变量,如果设置,则存储该值在$this->data
数组中呈现给模板:之后,您可以简单地在模板中回显这些值(仍然检查是否存在):
现在您应该完成,同时避免任何
未定义的变量
通知...Here I would save the variables into a session:
Now in
catalog/controller/checkout/guest.php
atindex
method check for that session variables and if set, store the value in the$this->data
array for presenting to the template:After that You can simply echo these values in Your template (still checking whether exists):
Now You should be done while avoiding any
undefined variable
notices...没有保存会话变量的文件。
打开购物车会话是使用“system/library/Session.php”创建的。您可以在打开的购物车中创建这样的会话。
现在您可以在打开购物车的任何位置调用此会话,如下所示。
There is no file that held the session variables.
Open cart session are created by using "system/library/Session.php". You can create session like this in open cart.
Now you can call this session in any where in open cart like this.
我想我有点晚了,但是处理会话的主类位于 system/library/session.php 中,它具有公共变量 $data 并在构造函数中处理 $_SESSION 。
所以你在 $this->session->data 中放入的内容都会合并。
希望它会有好处。
谢谢
I think i bit late but the main class which handle the sessions is in the system/library/session.php, which have public variable $data and handling the $_SESSION in the constructor.
so what ever you put in the $this->session->data it merge.
Hope it will be beneficial.
thanks
/system/library/customer.php 确实包含 $this->session->data['customer_id'];
/system/library/customer.php does contain $this->session->data['customer_id'];