Sorry - little information. Describe in more detail the model, database and which tables will be used.
In general, a typical approach - Gii suggests it by the way - you make its inherited version of a Model to a Model; Model Gii will generate you a model in which it will write: / ** * A Model represents your models\Модель . * / class ModelSearch extends Model
In the search model itself, you can arbitrarily add as many parameters as you like to the search method used in the grid. It is difficult to guess what kind of obd you have, but for example how it might look (from me). I can not say that all approaches here are the only true ones, but it shows the meaning and methods of use.
public function search($params, $type = 1, $map = null, $paginationOff = null) { $query = Product::find(); if (isset($params['type']) && in_array($params['type'], array_flip(Product::getTypes()))) { $this->setAttribute('type', $params['type']); } else { $this->setAttribute('type', $type); } $this->load($params); // array load $type2 = @$params['ProductSearch']['type2']; $appPlatforms = @$params['ProductSearch']['appPlatforms']; $country = @$params['ProductSearch']['country_id']; $apps_count = @$params['ProductSearch']['apps_count']; $appCategory = @$params['ProductSearch']['appCategory']; $qty_staff = @$params['ProductSearch']['qty_staff']; $since_date = @$params['ProductSearch']['since_date']; $title = @$params['ProductSearch']['title']; $city = @$params['ProductSearch']['city_id']; $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => self::PAGE_SIZE ], ]); if ($paginationOff) { $dataProvider->pagination = false; } $query->andFilterWhere([ 'uid' => $this->uid, 'type' => $this->type, ]); // Ключевое слово if ($title) { $query->andFilterWhere(['like', 'Product.title', $title]); } // Type2 parametr if ($type2) { if (is_array($type2)) { foreach ($type2 as $item) { $query->andFilterWhere(['Product.type2' => $item]); } } } // Страна if ($city) { if (is_array($city)) { $query->andFilterWhere(['in', 'Product.city_id', $city]); } } if ($country) { if (is_array($country)) { $query->andFilterWhere(['in', 'Product.country_id', $country]); } } // Колличество сотрудников if ($qty_staff) { if (is_array($qty_staff)) { $query->andFilterWhere(['in', 'Product.qty_staff', $qty_staff]); } } // Год основания if ($since_date) { if (is_array($since_date)) { $query->andFilterWhere(['in', 'Product.since_date', $since_date]); } } // технологии if (@$params['ProductSearch']['_tech']) { $query->leftJoin('technology', '`technology`.`Product_uid` = `Product`.`uid`'); $query->andFilterWhere(['`technology`.title' => $this->_tech]); } // Специализация if (@$params['ProductSearch']['_spec']) { $query->leftJoin('specialization', '`specialization`.`Product_uid` = `Product`.`uid`'); $query->andFilterWhere(['`specialization`.title' => $this->_spec]); } if ($this->type == 1) { // приложения $query->leftJoin('app_to_dev', '`app_to_dev`.`devId` = `Product`.`uid`'); $query->leftJoin('application', '`application`.`id` = `app_to_dev`.`appId`'); $query->leftJoin('app_developer', '`app_developer`.`devId` = `Product`.`uid`'); $query->leftJoin('application as applicationDev', '`applicationDev`.`developer_native_id` = `app_developer`.`native_id`'); $query->select(['Product.*, count(`app_developer`.id) + count(`app_to_dev`.id) as count, `application`.`store` as store, `applicationDev`.`store` as store2']); $query->groupBy(['`Product`.`uid`']); if ($appPlatforms) { if (is_array($appPlatforms)) { if (count($appPlatforms) == 1) { foreach ($appPlatforms as $item) { $query->andFilterWhere(['or', ['`application`.`store`' => $item], ['`applicationDev`.`store`' => $item]]); } } elseif (count($appPlatforms) > 1) { $query->andFilterWhere(['or', ['in', '`application`.`store`', $appPlatforms], ['in', '`applicationDev`.`store`', $appPlatforms]] ); } } } return $dataProvider; }