/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Site::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'lat', $this->lat])->andFilterWhere(['like', 'lng', $this->lng])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'taxId', $this->taxId])->andFilterWhere(['like', 'site_type', $this->site_type]); return $dataProvider; }
/** * Finds the Site model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Site the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $model = Site::find()->where(['id' => $id])->with('materials')->one(); if ($model !== null) { return $model; } else { Yii::$app->response->format = 'json'; Yii::$app->response->setStatusCode(404); return ['message' => 'Record not found']; die; } }
public function actionGetSites($q) { $query = Site::find()->select(['s.id', 's.name'])->from(['s' => Site::tableName()]); if (empty($q)) { $query->andWhere(['or', ['like', 's.name', $q]]); } $list = $query->all(); $result = []; foreach ($list as $site) { $domain_arr = ArrayHelper::getColumn($site->domains, 'domain'); $result[] = ['value' => $site->name . "|" . implode('|', $domain_arr), 'data' => $site->id]; } $response = Yii::$app->response; $response->format = $response::FORMAT_JSON; return $result; }