php - Missing Required Parameter in Yii2 Gridview Action Button -
i'm trying add own action button in yii2-kartik gridview. custom button:
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
Post a Comment