public function getDiseasesByCondition($param = [], $offset = 0, $length = 10) { $where = ''; $bound = []; foreach ($param as $k => $v) { if (!empty($v)) { $where .= ' and ' . $k . ' = :' . $k; $bound[':' . $k] = $v; } } $where = substr($where, 5); $where = !empty($where) ? $where : ''; return Disease::find()->select("id,name,class_level1,class_level2,source")->where($where, $bound)->offset($offset)->limit($length)->asArray()->all(); }
/** * ajax 获取疾病 */ public function actionGetDisease() { $request = Yii::$app->request; if ($request->isPost) { $class_level1 = $request->post('class_level1', ''); $class_level2 = $request->post('class_level2', ''); $name = $request->post('name', ''); //疾病名称 $page = $request->post('page', 1); //页码 $condition = []; if (!empty($class_level1)) { $condition['class_level1'] = $class_level1; } if (!empty($class_level2)) { $condition['class_level2'] = $class_level2; } if (!empty($name)) { $condition['name'] = $name; } $obj_disease = new Disease(); $total = $obj_disease->getCounts($condition); $length = 10; $paging = $this->helpPaging('pager_department')->setSize($length)->setPageSetSize(5); $offset = $paging->getOffset(); $paging->setTotal($total); $res = $obj_disease->getDiseasesByCondition($condition, $offset, $length); $data = []; $data['disease'] = $res; $data['page_html'] = $paging; $data['page'] = $page; return $this->renderPartial('add_disease_search', $data); } }