/** * 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; }
public function getSite() { return $this->hasOne(Site::className(), ['id' => 'site_id']); }
/** * 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; } }
/** * Updates an existing Node model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $model->scenario = 'update'; $parent = Node::findOne($model->parent); $site = Site::findOne($model->site_id); if (isset($parent)) { $model->parent_txt = $parent->name; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'site' => $site]); } }
/** * 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) { if (($model = Site::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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; }