I add such select in the view

<select name="list"> <option value="mouse">mouse</option> <option value="keyboard">keyboard</option> <option value="headphones">headphones</option> </select> 

In the model created

 $list = Yii::$app->request->post('list', 'mouse') $result = Yii::$app->getDb()->createCommand(' Select * from order_table where items_sort in :list ')->bindValue(':list', '('.$list.')') ->queryAll(); return $result; } 

The controller looks like this

  public function actionIndex() { $data = null; if(isset($_GET['last_month'])) { $data = order::getTest(); } $dataProvider = new ArrayDataProvider([ 'allModels' => $data, 'sort' => [ ], 'pagination' => [ 'pageSize' => 50, ], ]); return $this->render('index',['dataProvider' =>$dataProvider]); } 

But when selecting any value, the default value is substituted into the query. What could be the problem? Form Code

 <div style="width: 25%; margin: 0 auto; text-align: center;"><br> <?php $form1 = ActiveForm::begin(['id' => 'last_month', 'method' => 'GET']); ?> <input type="hidden" value="0" name="last_month"> <div class="form-group" style="float:left;margin-left: 5px;"> <?= Html::submitButton('Прошлый <br> месяц', ['class' => 'btn btn-primary', 'name' => 'n1', 'style'=>"width:120px;display:inline-block;"]) ?> </div> <?php ActiveForm::end(); ?> <?php $form = ActiveForm::begin(['id' => 'pre_last_month', 'method' => 'GET',]) ?> <input type="hidden" value="1" name="pre_last_month"> <div class="form-group" style="float:left;margin-left: 5px;"> <?= Html::submitButton('Позапрошлый <br> месяц', ['class' => 'btn btn-primary', 'name' => 'nn',]) ?> </div> <div style="clear:both;"></div> <?php ActiveForm::end(); ?></div> <form method=post> <select name="list"> <option value="vari-cream-com">vari-cream-com</option> <option value="joint-cream">joint-cream</option> <option value="gemor-cream">gemor-cream</option> </select> </form> 

    1 answer 1

    I think a mistake in the model, you have inserted
    $list = Yii::$app->request->post('list', 'mouse')
    try without a mouse
    $list = Yii::$app->request->post('list')

    • then in general it gives an error, for some reason nothing gets into the $list . - cruim
    • @cruim Then, apparently, the problem is that POST is not sent, or not POST. - ilyaplot
    • What error gives? I think the problem with sending, it would be nice to see the form code completely - Arsen
    • @Arsen added form code - cruim
    • @cruim but where does your form send data? you just inserted the bare form, YII has its own standards for working with forms (ActiveForm) just one answer does not help you, read the documentation yiiframework.com/doc/guide/1.1/ru/form.view - Arsen