如何使 GridView 按钮更新和删除仅对管理员可见? [英] How to make that GridView buttons update and delete just only visible for admins?

查看:31
本文介绍了如何使 GridView 按钮更新和删除仅对管理员可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Yii2 的新手,我有 3 种用户权限:

I am new to Yii2 and I have 3 kind of user rights:

Adminmoderatoruser.我有我的 GridView,我不想向用户显示 UpdateDelete 按钮,只显示 GridView.我该怎么做?

Admin, moderator and user. I have my GridView and I don't want to show for the user the Update and Delete buttons, just only the GridView. How should I do that?

这是我的actionCreate,有一个输入表单:

Here is my actionCreate, there is an input form:

    public function actionCreate()
{
    $model = new Project();
    $model->scenario = Project::SCENARIO_CREATE;

    if ($model->load(Yii::$app->request->post())) {
        if ($model->save()) {
            Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Skelbimas sėkmingai pridėtas!'));
            return $this->redirect(['index']);
        }
    }
    return $this->render('create', [
        'model' => $model,
    ]);
}   

我尝试根据此搜索信息,但找不到有用的信息.感谢您提供任何帮助或信息.

I've tried to search the information according to this, but couldn't find useful ones. Thanks for any help or information.

推荐答案

要实现这一点,您必须使用属性 $visibleButtons 你的 ActionColum 类.

To accomplish this, you have to use the property $visibleButtons of you ActionColum class.

所以:

'visibleButtons' = [
    'update' => Yii::$app->user->can('update'), // or whatever condition
    'delete' => Yii::$app->user->can('update')
]

等等.visibleButtons 数组上的每个 Key 都是按钮的名称.

and so on. Each Key on the visibleButtons array is the name of the button.

Yii 框架指南

这篇关于如何使 GridView 按钮更新和删除仅对管理员可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆