model = model('ClientSearchKeyword'); $this->view->assign("sexList", $this->model->getSexList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ public function add() { if ($this->request->isAjax()) { $ids = $this->request->get('ids'); $row = model('Book')->field('id,name,sex')->where('id', 'in', $ids)->select(); $params = []; $i =0; foreach ($row as $value) { $keywordexists = []; $keywordexists = model('ClientSearchKeyword')->get(['keyword' => $value['name']]); if(empty($keywordexists)){ $params[$i]['keyword'] = $value['name']; $params[$i]['book_id'] = $value['id']; $params[$i]['sex'] = $value['sex']; $i = $i+1; } } model('ClientSearchKeyword')->saveAll($params); $this->success('添加成功' .json_encode($ids)); } $this->error("非Ajax请求"); return $this->view->fetch(); } }