model = new \app\api\model\ImageStorages(); } public function index() { //接受参数 $_get = $this->request->get(); //指定搜索参数 $this->model->search_arr = ['title']; //数据处理 $_data = $this->model->index(); //返回数据 return send_http_status($_data); } public function read(int $id = 0) { //验证参数 validate(\app\api\validate\Message::class)->scene('read')->check(['id' => $id]); //返回数据 return send_http_status($this->model->parentRead($id)); } public function add() { //接收参数 $_post = $this->request->post(); //处理并返回参数 $insertId = $this->model->parentAdd($_post); return send_http_status($insertId, $insertId ? 201 : 202); } public function edit(int $id = 0) { //接收参数 $_post = $this->request->post(); $_post['id'] = empty($_post['id']) ? $id : 0; //安全赋值,以免客户端没传id,修改需要id字段 //处理并返回数据 return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204); } public function delete() { //接收参数 $ids = $this->request->param('id'); //验证参数 validate(['ids|id' => 'require|length:1,1000'])->check(['ids' => $ids]); //处理并返回数据 return send_http_status('', $this->model->parentDel($ids) ? 205 : 206); } }