Issue
I am using cakephp v3.x
Below is my login function.
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
} //public function login()
I am trying to get the username who tried to log in. I tried reading http://book.cakephp.org/3.0/en/controllers/components/authentication.html I am not able to find the API to retrieve the username. How can this be done?
Solution
You will get all details for user :
$user_details = $this->Auth->User();
echo $user_details['username'];
Answered By - Lakhan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.