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

Yii2 - Pass variable from view to Gridview custom action columns

我想保存用户在单击页面的 gridview 小部件中的 "Edit" 按钮之前访问的最后一个位置。我创建了一个名为 $lastAddress 的变量,但我真的不知道如何将它传递到 gridview 并将其附加到 "Edit" 按钮的 $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);
},