如何获取Prestashop当前用户id?

如何获取Prestashop当前用户id?,prestashop,custom-error-pages,Prestashop,Custom Error Pages,我使用下面的代码试图在prestashop中获取当前用户ID。。 我将此代码放在模块目录中的另一个php文件中,并通过模块文件调用它 $id = $this->context->customer->id_customer; 但这对我不起作用。。我正在使用prestashop 1.5..我当然也无法在测试中使用它。不过,你可以试试 $id = (int)$this->context->cookie->id_customer; 这对我很有用。我不确定这是否是

我使用下面的代码试图在prestashop中获取当前用户ID。。 我将此代码放在模块目录中的另一个php文件中,并通过模块文件调用它

 $id = $this->context->customer->id_customer;

但这对我不起作用。。我正在使用prestashop 1.5..

我当然也无法在测试中使用它。不过,你可以试试

$id = (int)$this->context->cookie->id_customer;

这对我很有用。我不确定这是否是最好的方法。

首先检查用户是否已登录,然后通过
$this->context->customer->id\u customer

if ($this->context->customer->isLogged()) {

      echo $this->context->customer->id_customer;

}
else{
   echo 'Not LoggedIn';
}

你不应该用饼干

只要用这个:

    $id=(int)$this->context->customer->id;
您可以删除(int),但我喜欢指定我获取的内容的类型


BR

在Prestashop 1.6中,控制器的最佳方式是使用:

        $id_customer = null;
        if ($this->context->customer->isLogged()) {
            // code to execute if i am logued
             $id_customer = $this->context->customer->id;
        }

你能提供更多的细节吗?你想在你的php文件中做什么?你在前台还是后台?您的php文件是用ajax调用的吗?我们需要背景来理解问题的来源。我已经得到了答案