I am new to Yii2 and I have 3 kind of user rights
:
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?
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.
To accomplish this, you have to use the property $visibleButtons of you ActionColum class.
So:
and so on. Each Key on the visibleButtons array is the name of the button.
Yii Framework's guide
One possibility would be using the
'template'
attribute of youe'ActionColumn'
like:Please, bare in mind that even though this solution will hide the buttons for users with only
user
right, it won't prevent them of accessing update and delete action urls, so you have to check permissions also in the controller level.