mailModel = new \app\user\model\Mail(); $this->userModel = new \app\user\model\User(); } public function index(){ $p = $this->request->get('page', 0); $nick = $this->request->get('n'); $where = []; if($nick) $where['title'] = ['like', "%$nick%"]; $info = $this->mailModel->getInfo($p, $where); $page = $this->mailModel->getPage($where); $this->assign("info", $info); $this->assign("page", $page); return $this->fetch(); } public function edit(){ $id = $this->request->get('id'); $info = $this->mailModel->getMailById($id); $this->assign("info", $info); return $this->fetch('edit'); } public function select(){ if($this->request->isAjax()){ $p = $this->request->get('page', 0); $limit = $this->request->get('limit'); $nick = $this->request->get('n'); $id = $this->request->get('i'); $where = []; if($nick) $where['nickname'] = ['like', "%$nick%"]; if($id) $where['id'] = ['=', $id]; $count = $this->userModel->where($where)->count(); $data = $this->userModel ->where($where) ->page($p, $limit) ->order('registertime', 'desc') ->select(); // 需要把long类型转换成字符串,不然js无法解析 foreach($data as &$val){ $val['id'] = strval($val['id']); } $result = ['code'=>0, 'msg'=>'success', 'count'=>$count, 'data'=>$data]; return json($result); } $this->view->engine->layout(false); return $this->fetch(); } public function save(){ $res = $this->mailModel->addAndSave(); if($res){ $this->success('保存成功!', 'index'); }else{ $this->error('保存失败!'); } } }