/** * Spec list. * * @return mixed * @throws BadRequestHttpException */ public function actionSpecList($q = null, $id = null) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $out = ['results' => ['id' => '', 'text' => '']]; if (!is_null($q)) { $query = new Query(); $query->select('id, CONCAT_WS(" ", `code`, `name`) AS text')->from('spec')->where(['like', 'name', $q])->OrWhere(['like', 'code', $q])->limit(20); $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => Spec::find($id)->name]; } return $out; }
/** * Lists all Spec models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Spec::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }