Ckappo
Ckappo

Reputation: 597

How to find user datas in cakePHP3

i just startet to play with CakePHP3 and create a simple Authentication.

I create a simple Authentication with username & wassword.

In my view I want to show user details from my "User" table.

I want to find ID and USERNAME:

$username =  $this->Auth->user('id');
$userid   =  $this->Auth->user('username');

I get the correct Informations. But when I want find the other informations I don't get any Result:

$userrole =  $this->Auth->user('role');

He alway find nothing (NULL).

How can I find the "User role"? Must I create an query to find it?

Upvotes: 0

Views: 80

Answers (1)

user1134181
user1134181

Reputation:

AuthComponent::user($key = null)

The user() function returns any column from the currently logged in user:

// From inside a controller or other component.
$this->Auth->user('id');

If the current user is not logged in or the key doesn’t exist, null will be returned.

See also:

Upvotes: 1

Related Questions