Detailview Wiget To Limit The Viwable Fields For Certain Users


I’m wondering if there is any option to limit the visibility of some sensitive information when using the DetailView?

For example an email. Not all users are allowed to view another user’s email especially if it is a guest.

Please let me know how i can achieve this.


i think i found the answer :lol:

using this method will give me the option when to display some fields.


Use the visible property to control each attribute you display. A simple example below:

echo DetailView::widget([

    'model' => $model,

    'attributes' => [

        ['attribute'=>'email', 'visible'=>!Yii::$app->user->isGuest]