我了解 ActionColumn 按钮的可见性可以这样控制:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
'body:ntext',
// ['class' => 'yii\grid\ActionColumn'],
[
'class' => 'yii\grid\ActionColumn',
'visibleButtons' =>
[
'update' => Yii::$app->user->can('updatePost'),
'delete' => Yii::$app->user->can('updatePost')
]
],
],
]);
?>
Run Code Online (Sandbox Code Playgroud)
我已经创建了 RBAC 授权,以及一个基于 yii2 文档的 AuthorRule Rule 类
http://www.yiiframework.com/doc-2.0/guide-security-authorization.html
在 roleParams 的情况下,我已经实现了如下(在视图模板中):
if (\Yii::$app->user->can('updatePost', ['post' =>$model]){
//if the post is created by current user then do this
}
Run Code Online (Sandbox Code Playgroud)
如何找出 GridView 小部件中的模型或至少 id 以便我执行以下操作:
'visibleButtons' =>
[
'update' => …Run Code Online (Sandbox Code Playgroud)