PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] How to find user datas in cakePHP3

 March 19, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

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?


Solution

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:

  • Accessing the Logged In User


Answered By - user1134181
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing