Data in the save method of the Yii execution model is empty.

Source: Internet
Author: User
: This article mainly introduces that the data in the save method of the Yii execution model is empty. if you are interested in the PHP Tutorial, refer to it. Test Environment: Yii2.0 basic

Namespace app \ models;
UseYii;
Use yii \ base \ NotSupported Exception;
Use yii \ behaviors \ TimestampBehavior;
Use yii \ db \ ActiveRecord;
Use yii \ web \ IdentityInterface;

Clas User extends ActiveRecord implements IdentityInterface {
/*
* If
* Public $ username
* Public $ password
* When we update the model, the $ name data is not mapped to the data model,
* When data is submitted, fields in the table corresponding to the variables defined by public are empty.
*
*/
}

It is tested that using protected and private to declare local variables can be written normally. Scope relationship

$ Model = new User ();

$ Model-> username = $ username;

$ Model-> password = $ password;

Assume that the model User declares

Public $ username;

Public $ password;

Therefore, when assigning values to $ model-> username, it is equivalent to assigning values to the public variable in the User model, rather than the username field value mapped by the AR model itself.

Conclusion: The public variable names with the same model declaration and data table field names are not allowed.

The data in the save method of the Yii execution model is null, including the Exception content, and it is helpful to anyone interested in the PHP Tutorial.

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.