????:<?php namespace app\admin\controller; use Util\SysDb; use think\facade\Request; use app\admin\model\AdminModel; class Admin extends Base { &nbs
<?php namespace app\admin\controller; use Util\SysDb; use think\facade\Request; use app\admin\model\AdminModel; class Admin extends Base { public function index() { // 加載管理員列表 $list = SysDb::getnstance()->table('admins')->order('id desc')->lists(); $this->assign('lists',$list); return $this->fetch(); } // 添加管理員 public function add() { return $this->fetch(); } // 添加操作 public function doAdd() { // 獲取上傳數(shù)據(jù) $data = Request::param(); // 生成密文 $data['password'] = sha1($data['password']); // 生成時(shí)間 $data['add_time'] = time(); // 查看用戶名是否存在 $find = AdminModel::get($data['username']); if($find) { return ['code'=>0,'msg'=>'用戶名已存在,請(qǐng)重新輸入']; } // 否則寫入數(shù)據(jù)表 $ins = AdminModel::create($data); if($ins) { return ['code'=>1,'msg'=>'用戶添加成功']; } return ['cdoe'=>0,'msg'=>'用戶添加失敗']; } // 編輯頁(yè)面 public function edit() { // 接收ID $id = Request::param('id'); $id = (int)$id; // 查詢一條數(shù)據(jù) $data = AdminModel::where(['id'=>$id])->find(); // 模板賦值 $this->assign('data',$data); // 渲染視圖 return $this->fetch(); } // 編輯操作 public function doEdit() { // 接收上傳數(shù)據(jù) $data = Request::param(); // 獲取ID $id = $data['id']; unset($data['id']); // 更新數(shù)據(jù) if($data['password']) { $data['password'] = sha1($data['password']); } else { unset($data['password']); } $up = AdminModel::where('id',$id)->update($data); if($up) { return ['code'=>1,'msg'=>'數(shù)據(jù)更新成功']; } return ['code'=>0,'msg'=>'數(shù)據(jù)更新失敗']; } // 刪除操作 public function delete() { // 接收刪除條件 $id = Request::param(); $id = (int)$id; // 刪除 $res = AdminModel::destroy($id); if(!$res) { return ['code'=>0,'msg'=>'刪除失敗']; } return ['code'=>1,'msg'=>'刪除成功']; } }
?? ???:查無(wú)此人?? ??:2019-05-05 09:24:52
???? ??:完成的不錯(cuò)。tp框架一直占用率比較高。要好好學(xué)。繼續(xù)加油。