For more information about cakephp, see the cakephp code. Why does AuthComponent: user ('id') fail to get the value? how can this problem be solved?

Source: Internet
Author: User
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 ());
}
///.....
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.