: 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.