I want to save the last place that a user visited before he click onto "Edit" button in the gridview widget of a page. I created a variable named $lastAddress but I really dont know how to pass it onto the gridview and append it to the $url variable of "Edit" button. Can anyone show me how?
$lastAddress = 'xxx'; <?= GridView::widget([ ... [ 'class' => 'yii\grid\ActionColumn', 'template' => '{view} {update} {delete}', 'buttons' => [ 'update' => function ($url, $model) { $url .= '&lastAddress=' . $lastAddress; //This is where I want to append the $lastAddress variable. return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url); }, ], ], ], ]); ?>
Use use
to pass in variables from the parent scope to a closure:
'update' => function ($url, $model) use ($lastAddress) { $url .= '&lastAddress=' . $lastAddress; //This is where I want to append the $lastAddress variable. return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url); },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With