gpt4 book ai didi

gridview - Yii2 - 将变量从 View 传递到 Gridview 自定义操作列

转载 作者:行者123 更新时间:2023-12-02 16:42:00 24 4
gpt4 key购买 nike

我想保存用户在单击页面的 gridview 小部件中的“编辑”按钮之前访问的最后一个位置。我创建了一个名为 $lastAddress 的变量,但我真的不知道如何将其传递到 gridview 并将其附加到“编辑”按钮的 $url 变量中。谁能告诉我怎么做?

$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将变量从父作用域传递到闭包:

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

关于gridview - Yii2 - 将变量从 View 传递到 Gridview 自定义操作列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31241336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com