abstrakt:controller下添加管理員操作方法public function add(){renturn $this->fetch();}public function DoAdd(){//獲取前端提交數(shù)據(jù)$data = Request::param();//獲取添加時(shí)間$data['time'] = time();$username = data['username
controller下添加管理員操作方法
public function add(){
renturn $this->fetch();
}
public function DoAdd(){
//獲取前端提交數(shù)據(jù)
$data = Request::param();
//獲取添加時(shí)間
$data['time'] = time();
$username = data['username'];
//使用用戶名查詢數(shù)據(jù)是否有對應(yīng)數(shù)據(jù)
$res = UserModel::where('username',$username)->find();
//判斷數(shù)據(jù)是否存在
if ($res == true ){
return [ 'res'=>0,'msg'=>'用戶名已存在'];
}
//實(shí)例化模型
$user = new UserModel();
//驗(yàn)證數(shù)據(jù)是否加入成功
if($user=>save($data)){
return ['res'=>1, 'msg'=>'添加成功!'];
}else{
return [ 'res'=>0, 'msg'=>'添加失敗'];
}
}
Korrigierender Lehrer:天蓬老師Korrekturzeit:2019-04-22 09:41:50
Zusammenfassung des Lehrers:代碼完整, 注釋清楚, 不錯(cuò)的...., 默認(rèn)從后端返回的數(shù)據(jù)類型是json格式