Dijo
Dijo

Reputation: 73

Can't get the parameter passed from view to controller in Yii2

I am passing a value($model->stop) of my form to controller action(search2) via button click.But I can't get that value in the controller.

view:

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

Controller:

  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,
        ]);
      }
  }

Error:

    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.

Help me to solve this.

Upvotes: 1

Views: 434

Answers (1)

saurssaurav
saurssaurav

Reputation: 773

All your code seems right, I think problem is with $model->stop value

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

please check.

Upvotes: 2

Related Questions