我尝试添加额外的操作按钮。管理员仅在数据库中的单个字段中单击更新按钮后查看此按钮。
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->can('admin')){
}
?>
</p>
我的问题是我有3个用户:申请人,教师和 admin (或hod)。在这种情况下,在教师推荐之后,管理员(或hod)批准了休假。
我建议离开应用程序和教师,所以现在我想在管理员登录网站时获取推荐的数据。
答案 0 :(得分:1)
如果admin是用户名,您应该遵循以下方式:
<p>
<?php
if(!Yii::$app->user->isGuest ){
echo Html::a('Recommended', ['update', 'id' => $model->id],
['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to reject this application?',
'method' => 'post',
],
]);
} else if(Yii::$app->user->identity->username == 'admin' ){
echo Html::a('Your Button Label for Admin',
['yourActionForAdmin', 'id' => $model->id],
['class' => 'btn btn-primary']);
}
?>
</p>