2013-04-26 21 views
6

私はprestashopで現在のユーザーIDを取得しようとしました.. このコードを私のモジュールディレクトリにある別のPHPファイルに置き、モジュールファイルで呼び出しています。Prestashopの現在のユーザーIDを取得するには?

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

が、そのは私のために働いていない..私は確かにそれはどちらか私のテストで動作させることができなかった。..

+0

あなたはより多くの詳細を与えることはできますか?あなたはあなたのPHPファイルで何をしようとしていますか?あなたはフロントオフィスかバックオフィスにいますか?あなたのPHPファイルはajaxで呼び出されていますか? 問題がどこから来るのかを理解するためには、コンテキストが必要です。 – AlexDeb

+0

私はすでに答えを得たAlexDeb – Manik

+1

http://blog.gofenice.com/uncategorized/get-current-user-id-prestashop/ –

答えて

12

をPrestaShopの1.5を使用しています。しかし、試すことができます

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

私のために働く。私はこれが最善の方法だと確信していません。ユーザーが$this->context->customer->id_customer

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

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

} 
else{ 
    echo 'Not LoggedIn'; 
} 
+0

http://blog.gofenice.com/uncategorized/get-current-user-id -prestashop/ –

7

最初のチェック場合は、クッキーを使用してはなりません。

ただ、この使用:あなたは(int)を削除することができますが、私は取得コンテンツイムのタイプを指定したい

$id=(int)$this->context->customer->id; 

を。

BRの

+0

http://blog.gofenice.com/uncategorized/get-current-user-id-prestashop/ –

3

でIDを取得するよりも、ログインしている

+0

http://blog.gofenice.com/uncategorized/get-current-user-id-prestashop/ –

3

PrestaShopの1.6では、コントローラでの最良の方法は使用することです。

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

彼のラインを「コントローラの中に」追加するために投票された –

関連する問題