phpyii2yii-components

How to add a none-database row to a DetailView


I have 'view.php" file that have a yii\widgets\DetailView; on it.

    DetailView::widget([
        'model' => $model,
        'attributes' => [
            'feed',
            'feedname',
            ...
            'filename',
        ],
    ])

I want to add another 'attribute' that loads the 'filename' information into an <audio></audio> tag.

So is it as simple as:

            [
                'attribute' => '',
                'format' => 'raw',
                'value' => function ($model) {
                    // create the Tag
                    return $audioTag;
                },
            ],

Can I have a blank attribute? Can I just delete 'attribute' => '',?

Can I add an item in the model->attributeLabels and use it as the attribute and get a "Play this" in the header section?


Solution

  • You can leave out the attribute option if you specify both label and value.

    [
        'label' => 'Play this',
        'format' => 'raw',
        'value' => function ($model) {
            // create the Tag
            return $audioTag;
        },
    ],