Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Yii2 活动视图中按钮的可见性_Yii2 - Fatal编程技术网

Yii2 活动视图中按钮的可见性

Yii2 活动视图中按钮的可见性,yii2,Yii2,他的代码是my view.php <?php use yii\helpers\Html; use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $model app\models\CasualLeaves */ $this->title = $model->id; $this->params['breadcrumbs'][] = ['label' => 'Casual Leaves',

他的代码是my view.php

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\CasualLeaves */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Casual Leaves', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="casual-leaves-view">

<h1><?= Html::encode($this->title) ?></h1>

<p>
    <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
    <?= Html::a('Delete', ['delete', 'id' => $model->id], [
        'class' => 'btn btn-danger',
        'data' => [
            'confirm' => 'Are you sure you want to delete this item?',
            'method' => 'post',
        ],
    ]) ?>
    <?= Html::a(' Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
    <?= Html::a('Not Recommended', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
</p>


<?= DetailView::widget([
    'model' => $model,
    'attributes' => [
    //    'id',
        'name_of_applicant',
        'designation',
        'start_date',
        'end_date',
        'total_number_of_days',
        'reason_for_leave',
        'no_of_leave_already_taken',
        'date_of_request',
      //  'recommendation',
      //  'status',
    ],
]) ?>


我有一张请假申请表

申请人创建休假并保存

单击“创建”按钮后,申请人只能看到“更新”按钮,此时我想隐藏“删除”按钮


但是管理员在登录并检查应用程序时会查看删除按钮

只有当用户是管理员时,才可以使用删除按钮(在示例测试中,RBAC can('admin')权限)



你的问题不清楚。请提供更多细节。我也不知道你想做什么!?请再次描述问题:当前情况和问题以及预期行为。此代码不起作用,按钮已删除,但代码以如下形式显示:$model->id],'class'=>'btn-primary'])如果(!Yii::$app->user->isGuest){Html::a('Delete',['Delete',id'=>$model->id],'class'=>'btn-btn-danger',data'=>[“确认”=>“您确定要删除此项目吗?”,“方法”=>“发布”,],])}?>申请人姓名jhghj指定b开始日期2018-03-01结束日期2018-03-01总天数0请假原因cgdfg请假编号已请假日期1请假日期2018-03-01谢谢………我的代码在里面
<p>
<?php 

   echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
   if ( Yii::$app->User->can('admin') ){
     echo Html::a('Delete', ['delete', 'id' => $model->id], [
         'class' => 'btn btn-danger',
         'data' => [
             'confirm' => 'Are you sure you want to delete this item?',
             'method' => 'post',
         ],
    ]);
 }
echo Html::a('Recommended', ['update', 'id' => $model->id], 
         ['class' => 'btn btn-primary']);
echo Html::a('Not Recommended', ['update', 'id' => $model->id], 
         ['class' => 'btn btn-primary']);
?>
</p>