How to render youtube video in YII2 DetailView wid

2019-07-14 02:47发布

I'm displaying you-tube video on front end of the website. Admin can provide the you-tube source from embedded code from Site back end. I want to have a preview on view page. Following is the code I tried but it is displaying the iframe tags as it is (I know this is not the right way)

[
    'attribute'=>'source',
    'value' => !empty($model->source) ? '<iframe class="embed-responsive-item" src="'.$model->source.'" frameborder="0" allowfullscreen></iframe>' : NULL,
],

is there any thing like it has for image format:

[
    'label'=>'Image',
    'attribute'=>'userInfo.image',
    'format' => ['image',['width'=>'100','height'=>'100']],
],

1条回答
姐就是有狂的资本
2楼-- · 2019-07-14 03:18

Format html or raw will help you.

[
    'format' => 'raw',
    'attribute'=>'source',
    'value' => !empty($model->source) ? '<iframe class="embed-responsive-item" src="'.$model->source.'" frameborder="0" allowfullscreen></iframe>' : null,
],
查看更多
登录 后发表回答