public function search($params) { $query = Source::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['defaultOrder' => ['updatedOn' => SORT_DESC]]); $query->andFilterWhere([source::tableName() . '.status' => '1']); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['Id' => $this->Id, 'createdOn' => $this->createdOn, 'status' => $this->status, 'updatedOn' => $this->updatedOn, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Source::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
use common\models\Source; /** * @var yii\web\View $this * @var app\models\Restaurant $model * @var yii\widgets\ActiveForm $form */ ?> <div class="restaurant-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'sourceId')->dropDownList(ArrayHelper::merge([0 => 'Select'], ArrayHelper::map(Source::find()->andWhere(['status' => 1])->All(), 'Id', 'name'))); ?> <?php echo $form->field($model, 'entityType')->dropDownList([0 => 'Select', 1 => 'Restaurant', 2 => 'Nightlife']); ?> <?php echo $form->field($model, 'cityId')->dropDownList(ArrayHelper::merge([0 => 'Select'], ArrayHelper::map(\common\models\City::find()->andWhere(['status' => 1])->All(), 'Id', 'name'))); ?> <?php //$form->field($model, 'chainId')->dropDownList(ArrayHelper::merge([0=>'Select'], ArrayHelper::map(Brands::find()->andWhere(['status'=>1])->All(), 'Id', 'name'))) ?> <?php