Sankalp Sankalp - 1 month ago 5
PHP Question

Auth Component's user function not working in case multiple routing

I have routed my site as admin moderator. Means When I use Auth component my sessions are created as

Auth->Admin->id
&
Auth->Moderator->id
And
Auth->User->id
this way.

Now I tried function
$this->Auth->user
its returning null why??

As I know
$this->Auth->user
returns session.

I know the traditional way of
$this->Session->reads('Auth.Admin')
and else but I want to use Auth->user function why its not working

Answer

Please use this to get user session data.

public function login() {
 if ($this->request->is('post')) {
     if ($this->Auth->login()) {
    $this->redirect($this->Auth->redirect());
     } else {
    $this->Session->setFlash(__('Invalid username or password, try again'));
     }
 }
}

public function index() {
    pr($this->Auth->User());
}