Yii ActiveRecord save, little brother after I execute, why do I add a column to the database, but no data
Source: Internet
Author: User
Yii ActiveRecord Save, why do I add a column in the database, but no data?
Environment: Windows Ten + Wampservice + Yii2.0.6
Development tools: Phpstorm 9.0.2
Yii ActiveRecord Save, why do I add a column in the database, but no data?
What's the Official Handbook, why so many questions? Did I try a few, or did I say something wrong?
I built a model.
namespace App\models;
Use Yii\db\activerecord;
Class User extends ActiveRecord
{
public $username;
Public $password;
public static function model ($className =__class__)
{
Return Parent::model ($className);
}
public static function TableName ()
{
Return ' {{user}} ';
}
executing in the controller
$user = new User ();
$user->username = ' Hello ';
$user->password = ' world ';
$user->save ();
The database adds a column, but username and password are empty, only the previous ID, which I wrote in the database schema.
ID Int (TEN) unsigned NOT null primary key auto_increment.
executed in the browser
Localhost:80/yii/web/index.php?r=index/create execute without error, but view the database, add a column, but username and password are blank.
What should I do if I encounter this problem?
------to solve the idea----------------------
Print SQL to see the syntax for insert into, and also to check the structure of the table below.
------to solve the idea----------------------
If you encounter such debugging problems, you should first use Print_r ($user) to see if the $user is the result you want, and if the Public property field is correct, you should check that it is exactly the same as the table name in the database.
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.