Prestashop 自定义Cookie变量+;普雷斯塔什酒店

Prestashop 自定义Cookie变量+;普雷斯塔什酒店,prestashop,Prestashop,普雷斯塔什酒店 我被卡在了饼干的问题上。在prestashop 1.4.7中,我使用setcookie创建了一个自定义cookie变量,但当我尝试在front controller上访问并分配它时,我没有得到cookie设置值。 这是我的剧本: 页面:checkpostcode.php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/init.php'); global $cooki

普雷斯塔什酒店

我被卡在了饼干的问题上。在prestashop 1.4.7中,我使用setcookie创建了一个自定义cookie变量,但当我尝试在front controller上访问并分配它时,我没有得到cookie设置值。 这是我的剧本:

页面:checkpostcode.php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
global $cookie;

setcookie("is_postcode_checked", 1, time()+600, "/", "", 1); // Set the cookie in basepath
在frontcontroller.php页面上: 我正在使用
$\u COOKIE
访问它,并将其分配到smarty数组中

'is_postcode_checked' => $_COOKIE['is_postcode_checked'] // Getting null value for cookie
页面:检查邮政编码.tpl

{$cookie->_get(postcode_checked_msg)}  // here get the is_postcode_checked value but 

但我无法获取
是否已检查邮政编码
变量值

您应该完全使用Prestashop自己的cookie类,而不是使用PHP
setcookie()
函数。该类使用“神奇方法”
\uuuu get()
\uuu set()
\uuu unset()
\uu isset()
,这些方法应该可以让您轻松地完成此操作

尝试使用“页面”代码(不确定如何执行,因为它看起来不像是一个额外的页面控制器):

在FrontController覆盖中:

global $cookie;

if (isset($cookie->is_postcode_checked))
    $is_postcode_checked = $cookie->is_postcode_checked;
else
    $is_postcode_checked = 0;

您可以将变量$is\u postcode\u checked分配给相应的smarty变量,以便在模板中使用。

如果要从Prestashop cookie类中获取cookie,也应将其存储在此类中

在控制器中使用
die()
函数,以确定cookie是否已设置


正如Paul所说,最好只使用全局
$cookie
类来存储和获取数据。

在prestashop 1.5中,不推荐使用全局类

要在cookie中设置某些内容,请执行以下操作:

在控制器中:

$this->context->cookie->__set($key,$value);
其他文件:

$context = Context::getContext();
$context->cookie->__set($finger_print,$result); 
$context = Context::getContext();
$context->cookie->key;
您可以通过以下方式访问您的价值:

在控制器中

$this->context->cookie->key
其他文件:

$context = Context::getContext();
$context->cookie->__set($finger_print,$result); 
$context = Context::getContext();
$context->cookie->key;

我必须在php文件中实现第一个代码段吗?我不能完全在tpl文件中完成这项工作?我不建议在.tpl文件中完成这项工作,但从技术上讲,您可以在tpl文件中完成几乎任何事情。