Opencart 中的会话变量

发布于 2024-12-20 21:08:18 字数 416 浏览 7 评论 0原文

有人可以解释会话变量保存在哪里吗?

我在控制器的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回眸一笑 2024-12-27 21:08:18

会话值未在文件中设置。如果要设置会话变量,请使用

$this->session->data['variable_name_here'] = 'data value here';

和 检索刚刚访问的值

$this->session->data['variable_name_here']

例如,要回显它,请使用

echo $this->session->data['variable_name_here'];

Session values are not set in a file. If you want to set a session variable, use

$this->session->data['variable_name_here'] = 'data value here';

and to retrieve the value you just access

$this->session->data['variable_name_here']

For example, to echo it use

echo $this->session->data['variable_name_here'];
落日海湾 2024-12-27 21:08:18

在这里,我将变量保存到会话中:

public function receive() {
    $this->session->data['guest_name'] = $this->request->post['name'];
    $this->session->data['guest_address'] = $this->request->post['address'];
}

现在在 catalog/controller/checkout/guest.phpindex 方法中检查该会话变量,如果设置,则存储该值在 $this->data 数组中呈现给模板:

if(isset($this->session->data['guest_name'])) { // it is enough to check only for one variable and only if it is set
    $this->data['guest_name'] = $this->session->data['guest_name'];
    $this->data['guest_address'] = $this->session->data['guest_address'];
}

之后,您可以简单地在模板中回显这些值(仍然检查是否存在):

<?php if(isset($guest_name)) { ?>
<div><?php echo $guest_name . ' - ' . $guest_address; ?></div>
<?php } ?>

现在您应该完成,同时避免任何 未定义的变量通知...

Here I would save the variables into a session:

public function receive() {
    $this->session->data['guest_name'] = $this->request->post['name'];
    $this->session->data['guest_address'] = $this->request->post['address'];
}

Now in catalog/controller/checkout/guest.php at index method check for that session variables and if set, store the value in the $this->data array for presenting to the template:

if(isset($this->session->data['guest_name'])) { // it is enough to check only for one variable and only if it is set
    $this->data['guest_name'] = $this->session->data['guest_name'];
    $this->data['guest_address'] = $this->session->data['guest_address'];
}

After that You can simply echo these values in Your template (still checking whether exists):

<?php if(isset($guest_name)) { ?>
<div><?php echo $guest_name . ' - ' . $guest_address; ?></div>
<?php } ?>

Now You should be done while avoiding any undefined variable notices...

随遇而安 2024-12-27 21:08:18

没有保存会话变量的文件。
打开购物车会话是使用“system/library/Session.php”创建的。您可以在打开的购物车中创建这样的会话。

<?php
     $this->session->data['session_name'] = 'session value';
?>

现在您可以在打开购物车的任何位置调用此会话,如下所示。

<?php
     echo $this->session->data['session_name'];
?>

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.

<?php
     $this->session->data['session_name'] = 'session value';
?>

Now you can call this session in any where in open cart like this.

<?php
     echo $this->session->data['session_name'];
?>
2024-12-27 21:08:18

我想我有点晚了,但是处理会话的主类位于 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

寂寞笑我太脆弱 2024-12-27 21:08:18

/system/library/customer.php 确实包含 $this->session->data['customer_id'];

/system/library/customer.php does contain $this->session->data['customer_id'];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文