For more information about cakephp, see the cakephp code. Why does the AuthComponent: user (id) fail to get the PHPcodefunctionlogin () {if (empty ($ this-& gt; request-& gt; data [User] [username]) orempty ($ this-& gt; request-& g understand cakephp to see why the cakephp code is :: user ('id') cannot get the 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 --------------------
Not put in session
------ Solution --------------------
This is generally the way to obtain user information.
$ This-> Auth-> user ();
Try it yourself,
My usage is like this
1. set $ this-> Auth attributes in beforeFilter in AppController.
2. in UsersController
Function login (){
If ($ this-> Auth-> login ()){
$ This-> redirect ($ this-> Auth-> redirect ());
}
///.....
}