/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserAdvert::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'pet_category_id' => $this->pet_category_id, 'status' => $this->status, 'old_price' => $this->old_price, 'price' => $this->price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'phone_1', $this->phone_1])->andFilterWhere(['like', 'phone_2', $this->phone_2])->andFilterWhere(['like', 'phone_3', $this->phone_3])->andFilterWhere(['like', 'phone_4', $this->phone_4]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getAdvert() { return $this->hasOne(UserAdvert::className(), ['id' => 'advert_id']); }
/** * @return \yii\db\ActiveQuery */ public function getUserAdverts() { return $this->hasMany(UserAdvert::className(), ['pet_category_id' => 'id']); }
/** * Finds the UserAdvert model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserAdvert the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserAdvert::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }