T
T
teodor7teodor72016-12-16 12:46:34
Yii
teodor7teodor7, 2016-12-16 12:46:34

Is it possible to include an array in where in Yii2?

I'm doing a search, in the search you can select many values ​​​​in the same category. There may be many.

$modelExchangeSearchForm = new ExchangeSearchForm();

        if ($modelExchangeSearchForm->load(Yii::$app->request->get()) && $modelExchangeSearchForm->validate()) {

            $orders = Order::find()                    
                    ->filterWhere([
                         'country_id' => $modelExchangeSearchForm->country_id,
                        'club_id' => $modelExchangeSearchForm->club_id,
                         'apartment_type_id' => $modelExchangeSearchForm->apartment_type_id,
                        'season_id' => $modelExchangeSearchForm->season_id,
                         'type' => $modelExchangeSearchForm->order_type,
                        'is_membership' => $modelExchangeSearchForm->is_membership,
                         'is_expertize' => $modelExchangeSearchForm->is_expertize,
                       'is_penalty' => $modelExchangeSearchForm->is_penalty,
                        'is_priced' => $modelExchangeSearchForm->is_priced,
                        'bonus_weeks' => $modelExchangeSearchForm->bonus_weeks,
                    ])
                    ->andFilterWhere(['>=', 'priced_value', $modelExchangeSearchForm->price_from])
                    ->andFilterWhere(['>=', 'priced_value', $modelExchangeSearchForm->price_from]);

Is there a possibility that the array could be embedded in the search.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-12-20
@teodor7teodor7

It's not clear what you mean, but it looks like this:

$orders = Order::find();      
foreach($some_array as $key=>$value){
$orders->andFilterWhere([$key=>$value]);
}
$orders->andFilterWhere(['>=', 'priced_value', $modelExchangeSearchForm->price_from]);
$orders->andFilterWhere(['>=', 'priced_value', $modelExchangeSearchForm->price_from]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question