亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

管理員添加模塊代碼

原創(chuàng) 2019-04-20 17:30:32 225
摘要: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ù)是否有對(duì)應(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'=>'添加失敗'];

}

批改老師:天蓬老師批改時(shí)間:2019-04-22 09:41:50
老師總結(jié):代碼完整, 注釋清楚, 不錯(cuò)的...., 默認(rèn)從后端返回的數(shù)據(jù)類型是json格式

發(fā)佈手記

熱門詞條