摘要:?phpnamespace Home\Controller;use Think\Controller;class FormController extends Controller{public function insert(){$Form = D('Form');if($Form->create()) {$result = $Form->add();if($resu
?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{
public function insert(){
$Form = D('Form');
if($Form->create()) {
$result = $Form->add();
if($result) {
$this->success('数据添加成功!');
}else{
$this->error('数据添加错误!');
}
}else{
$this->error($Form->getError());
}
}
}
如果主键是自增类型的话,add方法的返回值就是该主键的值。不是自增主键的话,返回值表示插入数据的个数。如果返回false则表示写入出错。
批改老师:西门大官人批改时间:2019-04-08 10:17:21
老师总结:数据写入理解的很好。纠正一下,如果主键是自增类型(不要求一定要自增,是主键就行)的话,add方法的返回值就是该主键的值