yiihideraw

How to hide a raw in view.php file using Yii2 Framework


I have this raw in my view.php file:

[
              'attribute' => 'Descrizione',
                'format' => 'html',
                'value' => function ( $model ) {
                return nl2br($model->Descrizione);
              },
              'label' => 'Descrizione',
                ],

What I want is to hide the entire field if the value don't contains any character, so if is = "" OR is NULL. So I want to hide the entire field "Descrizione". Which is the option that I have to add in this code? Thank you very much


Solution

  • Are you using Gridview or DetailView ?

    If DetailView, try :

    [
      'attribute' => 'Descrizione',
      'label' => 'Descrizione',
      'visible' => !empty($model->Descrizione),
      'format' => 'ntext',
    ],