public function search() { $search = TbTable::find(); if ($this->name > '') { $search->andWhere("fdName like :name", [":name" => "%" . $this->name . "%"]); } $pages = new Pagination(['totalCount' => $search->count(), 'pageSize' => 10]); $datas = $search->offset($pages->offset)->limit($pages->limit)->all(); return ['datas' => $datas, 'pages' => $pages]; }
public function actionSearch() { $keyword = trim(Yii::$app->request->post('keyword')); $model = TbTable::find(); if ($keyword > '') { $model->andWhere("fdName like :name", [":name" => "%" . $keyword . "%"]); } $count = $model->count(); $ret['total'] = $count; $model->select = ["id", "fdText as name"]; $model->limit = 30; $model->asArray = true; $ret['entity'] = $model->all(); echo json_encode($ret); }