Prestashop 1.5 Cookie的内容

时间:2013-04-19 14:48:59

标签: cookies prestashop

我需要在外部PHP页面中显示prestashop客户ID。

在官方文档http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development

我找到了php代码:

如果您需要从非PrestaShop代码访问PrestaShop cookie,您可以使用以下代码:

    include_once('path_to_prestashop/config/config.inc.php');
    include_once('path_to_prestashop/config/settings.inc.php');
    include_once('path_to_prestashop/classes/Cookie.php');
    $cookie = new Cookie('ps'); // Use "psAdmin" to read an employee's cookie.

所以我尝试了:

include_once('config/config.inc.php');
include_once('config/settings.inc.php');
include_once('classes/Cookie.php');
$cookie = new Cookie('ps'); 
$id_client = $cookie->id_customer;
echo $id_client;

但没有显示任何内容,我尝试了其他令牌,只有“date_add”正常工作

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

以下作品:

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

$cookie = new Cookie('ps'); 
$id_client = $cookie->id_customer;
echo $id_client;

include(dirname(__FILE__).'/footer.php');
我亲自测试过。包括id和firstname在内的所有内容都有效。看来你不应该包含classes / Cookie.php文件。而是将其替换为global $cookie确保更改包含文件的目录。