/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Country::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(['countryid' => $this->countryid]); $query->andFilterWhere(['like', 'countryname', $this->countryname])->andFilterWhere(['like', 'acronym', $this->acronym]); return $dataProvider; }
public function search($params) { $query = Country::find(); // join with relation `author` that is a relation to the table `users` // and set the table alias to be `author` $query->joinWith(['user' => function ($query) { $query->from(['u' => 'user']); }]); $query->from(['c' => $this->tableName()]); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['user.username'] = ['asc' => ['u.username' => SORT_ASC], 'desc' => ['u.username' => SORT_DESC]]; //$dataProvider->sort->defaultOrder = ['updated_at' => SORT_DESC]; // load the seach form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } // adjust the query by adding the filters $query->andFilterWhere(['c.id' => $this->id]); $query->andFilterWhere(['like', 'c.name', $this->name]); $query->andFilterWhere(['LIKE', 'u.username', $this->getAttribute('user.username')]); return $dataProvider; }
SCRIPT; $met_description = Yii::t('app', 'Introduce your business, Your business on the map, image gallery for your business, attachments for your business, Mark your business location in map'); $this->registerMetaTag(['property' => 'og:description', 'content' => $met_description]); $this->registerMetaTag(['name' => 'description', 'content' => $met_description]); $this->registerMetaTag(['name' => 'keywords', 'content' => $met_description]); ?> <div class="row"> <div class="col-md-2"> <?php $form = ActiveForm::begin(['id' => $searchModel->formName(), 'enableAjaxValidation' => false, 'enableClientValidation' => false, 'method' => 'get']); ?> <?php echo $form->field($searchModel, 'category_id')->widget(Select2::classname(), ['language' => Yii::$app->helper->getTwoCharLanguage(), 'size' => Select2::MEDIUM, 'options' => [], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 2, 'ajax' => ['url' => $categoriesListUrl, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {search:params.term}; }'), 'results' => new JsExpression('function(data,page) { return {results:data.results}; }')], 'initSelection' => new JsExpression($initCategoriesListScript)]]); ?> <?php echo $form->field($searchModel, 'country_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Country::find()->asArray()->all(), 'id', 'name'), 'language' => Yii::$app->helper->getTwoCharLanguage(), 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'pluginOptions' => ['allowClear' => true]]); echo $form->field($searchModel, 'province_id')->widget(DepDrop::classname(), ['data' => !$searchModel->country_id ? [] : ArrayHelper::map(Province::find()->where(['country_id' => $searchModel->country_id])->asArray()->all(), 'id', 'name'), 'type' => DepDrop::TYPE_SELECT2, 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'select2Options' => ['pluginOptions' => ['allowClear' => true], 'language' => Yii::$app->helper->getTwoCharLanguage()], 'pluginOptions' => ['depends' => ['search-country_id'], 'url' => Url::to(['/province/dep-list']), 'loadingText' => Yii::t('app', 'Loading...')]]); echo $form->field($searchModel, 'city_id')->widget(DepDrop::classname(), ['data' => !$searchModel->province_id ? [] : ArrayHelper::map(City::find()->where(['province_id' => $searchModel->province_id])->asArray()->all(), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select...')], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['allowClear' => true], 'language' => Yii::$app->helper->getTwoCharLanguage()], 'pluginOptions' => ['depends' => ['search-province_id'], 'url' => Url::to(['/city/dep-list']), 'loadingText' => Yii::t('app', 'Loading...')]]); ?> <?php echo $form->field($searchModel, 'title')->textInput(); ?> <?php echo $form->field($searchModel, 'address')->textInput(); ?> <?php echo Html::hiddenInput('view', $adverView, ['id' => 'hiddenViewMode']); ?> <div class="form-group"> <?php echo Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']);
public static function getCountriesList() { return ArrayHelper::map(Country::find()->orderBy('countryname ASC')->all(), 'countryid', 'countryname'); }