N
N
Nikolai2019-06-10 17:25:32
Yii
Nikolai, 2019-06-10 17:25:32

How to display html-code from the database, code?

How can you display a field from the database that stores the html code and get this code not as a string value, but as an html code?!
Here is the page code when we view the product:

<?php $img = $model->getImage(); ?>
    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'title',
//            'block_img',
      [
        'attribute' => 'imgbl',
        'value' => Html::img('@web/img/upload/' . $img->filePath , ['class' => 'admin__img-view']),
        'format' => 'html',
      ],
            'block_svg',
            'svg:ntext',   // поле для вывода html-кода
        ],
    ]) ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
noeer, 2019-06-10
@Delta01

[
    'attribute' => 'fieldName',
    'format' => 'html',
    'value' => function($data){
        return $data->fieldName;
    },
],

Replace fieldName with the name of the field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question