Understand CakePHP's help. Look at this cakephp code, why Authcomponent::user (' id ') can't get a value
PHP Code
function login () { if (empty ($this->request->data[' User ' [' username ']) or empty ($this->request-> data[' User ' [' Password ']) { $this->session->setflash (' Please intyped a valied account! '); } ElseIf ($this->auth->login ($this->request->data[' User ')) { $this->user->id= authcomponent: : User (' id '); $this->redirect ("/users/index"); } else{ $this->redirect ("/users/logout"); } }
------Solution--------------------
I didn't put it in the session.
------Solution--------------------
This is usually the way to get the user's information
$this->auth->user ();
Try it yourself,
That's how I use it.
1. Set $this->auth related properties in Beforefilter in AppController
2. In the Userscontroller
function Login () {
if ($this->auth->login ()) {
$this->redirect ($this->auth->redirect ());
}
///.....
}