Code in the controller: {code...} code in the model: {code...} code in the controller:
If (IS_POST) {if ($ model-> validate ($ model-> _ login_validate)-> create () {if ($ model-> login ()) {if ($ res = session ('returnurl') {session ('returnurl', null); $ returnUrl = $ res ;} else {$ returnUrl = U ('/');} $ this-> success ('login successful! ', $ ReturnUrl); die ;}$ this-> error ($ model-> getError ());}
Code in the model:
Public function login () {var_dump ($ this); die; // Print $ this here and the attributes username and password are not found, but why can we get the value of $ username below ?? $ Username = $ this-> username; $ password = $ this-> password; $ model = M ('member'); $ where ['username'] = $ username; $ user = $ model-> where ($ where)-> find ();...}
Reply content:
Code in the controller:
If (IS_POST) {if ($ model-> validate ($ model-> _ login_validate)-> create () {if ($ model-> login ()) {if ($ res = session ('returnurl') {session ('returnurl', null); $ returnUrl = $ res ;} else {$ returnUrl = U ('/');} $ this-> success ('login successful! ', $ ReturnUrl); die ;}$ this-> error ($ model-> getError ());}
Code in the model:
Public function login () {var_dump ($ this); die; // Print $ this here and the attributes username and password are not found, but why can we get the value of $ username below ?? $ Username = $ this-> username; $ password = $ this-> password; $ model = M ('member'); $ where ['username'] = $ username; $ user = $ model-> where ($ where)-> find ();...}
Is to use get to read non-existing properties in data, and then to data, you can also set the attribute, that is, directly add the attribute after the object.
Public function _ get ($ name) {return isset ($ this-> data [$ name])? $ This-> data [$ name]: null;} public function _ set ($ name, $ value) {// Set data object attributes $ this-> data [$ name] = $ value ;}
Yes. although I have never written this way, I have printed the object after create and found that these attributes exist.
$ Data ['name'] = 'thinkphp'; $ data ['email '] = 'thinkphp @ gmail.com'; $ User-> create ($ data ); // after the data object is created, you can directly read the data echo $ User-> name; echo $ User-> email; // You can also directly modify the created data $ User-> name = 'onethink '; // modify the name field data $ User-> status = 1; // add new field data
Http://www.kancloud.cn/manual...
This section is found in document 3.2.3. $ This-> name you access after you create (); this should be the created attribute
You var_dump ($ model); try ..