php - Missing Required Parameter in Yii2 Gridview Action Button -


i'm trying add own action button in yii2-kartik gridview. custom button: enter image description here

this code in index.php

[     'class' => 'yii\grid\actioncolumn',     'template' => '{edit}',     'buttons' => [         'edit' => function ($url, $model) {          return html::a('<button type="button" class="btn btn-edit-npwp"><i class="glyphicon glyphicon-plus-sign"></i></button>', $url, [              'title' => yii::t('app', 'edit'),              'data-toggle' => "modal",              'data-target' => "#mymodal",              'data-method' => 'post',              ]);          },      ],     'urlcreator' => function ($action, $model, $key, $index) {        if ($action === 'edit') {            $url = url::toroute(['vatout-faktur-out/add-data', 'id' => $model->fakturid], ['data-method' => 'post',]);            return $url;        }      } ], 

and action in controller.php

public function actionadddata($id) {     $model = new vatoutfakturout();     return $this->render('adddata', [                 'model' => $model,     ]); } 

i want process data row i've clicked button. but, return error

missing required parameters: id

why happen? , how fix this?

thanks

in urlcreator used if statement check, if action edit, , if is, add param id button url. otherwise doesnt have one, there's 2 solutions:

remove if statement from:

'urlcreator' => function ($action, $model, $key, $index) {      $url = url::toroute(['vatout-faktur-out/add-data', 'id' => $model->fakturid]);      return $url;  } 

or remove$id actionadddata() - because youre not using @ all:

public function actionadddata() {     $model = new vatoutfakturout();     return $this->render('adddata', [                 'model' => $model,     ]); } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -