无法在Yii2中获取从视图传递到控制器的参数

时间:2017-02-07 08:20:52

标签: yii2 yii2-advanced-app

我通过按钮点击将表单的值($ model-> stop)传递给控制器​​操作(search2)。但是我无法在控制器中获得该值。

视图:

<?= Html::a(Yii::t('app', 'Search'), ['search2','id' => $model->stop], ['class' => 'btn btn-success']) 

控制器:

  public function actionSearch2($id)
  {
      if ($model->load(Yii::$app->request->post())) {   
        $searchModel   = new ScheduleRouteSearch();
        $dataProvider1 = $searchModel->search1(Yii::$app->request-   >queryParams, $id);

        return $this->render('search', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider1,
        ]);
      }
  }

错误:

    Bad Request (#400)
    Missing required parameters: id
    The above error occurred while the Web server was processing your request.
    Please contact us if you think this is a server error. Thank you.

帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

你的所有代码似乎都是对的, 我认为问题在于$ model-&gt;停止值

$model->stop  // value might be null  --null value also gives missing parameter error

请检查。