Welcome to the Cookbook

loading...

5.2.5.9 user

The original text for this section has changed since it was translated. Please help resolve this difference. You can:

More information about translations

user(string $key = null)
  1. user(string $key = null)

このメソッドは、現在認証しているユーザの情報を提供します。この情報はセッションから取得されます。例は次のとおりです。

if ($this->Auth->user('role') == 'admin') {
    $this->flash('あなたは管理者権限でアクセスしています。');
}
  1. if ($this->Auth->user('role') == 'admin') {
  2. $this->flash('あなたは管理者権限でアクセスしています。');
  3. }

このメソッドは、ユーザのセッションデータを全て取得するためにも使えます。

$data['User'] = $this->Auth->user();
  1. $data['User'] = $this->Auth->user();

ユーザーがログインしていない場合、このメソッドは null を返します。