Class Projectaction extends action{
Protected $_map = Array (
' username ' + ' user ',//map username in the form? User field of data table
' Password ' + ' pwd ',//map the password in the form? The PWD field of the data table
);
Public Function Insert () {
$Project = D (' Project ');
if ($Project->create ()) {
echo "Create data object successfully!" ";
if ($Project->add ()) {
Echo ' Add data success ';
}else {
Echo ' Add data failed ';
}
}else{
Echo ' failed to create data object ';
}
}
}
Insert the form data into the table, the execution of the Insert function, the data object creation failed, ask you what is the problem?
Reply to discussion (solution)
Paste the contents of the Model project file
Paste the contents of the Model project file
Model project is not defined
Paste the contents of the Model project file
I wrote the next data can be inserted
Attached to the official manual can be seen in the manual http://doc.thinkphp.cn/manual/create.html
Above is the form code
The fields of the data table are ID, user, PWD, respectively.
Protected $_map = Array (
' username ' + ' user ',//map username in the form? User field of data table
' Password ' + ' pwd ',//map the password in the form? The PWD field of the data table
);
Put it in the Projectmodel.