yii2:use video in use yii\bootstrap\Html

1.7k Views Asked by At

i want use video in DetailView

  'attribute' => ['media_id',
                'format' => 'html',
                'value' => function ($model)
                    {


                    $image = app\models\Media::find()->where(['id' => $model->media_id])->asArray()->one();



                $url = $image['url'];

                $host = Yii::$app->params['uploadPath'];

                return Html::video("$host/" . $url, ['width' => '60px']);
                },
            'label' => 'عکس',
        ],

how to use video in HTML for this section?

this is my error for use video :

name":"Exception","message":"Call to undefined method yii\\bootstrap\\Html::video()"
1

There are 1 best solutions below

4
On

There is not a HtmlHeper Html::video() function so you should use flat video tag eg:

Assuming you are using a DetailView widget you should use

echo DetailView::widget([
  'model' => $model,

  'attributes' => [
              [
                'format' => 'raw',  // or html
                'value' => function  ($model)  {

                    $image = app\models\Media::find()->where(['id' => $model->media_id])->asArray()->one();
                    $url = $image['url'];
                    $host = Yii::$app->params['uploadPath'];
                    return '<video width="60" height="240" controls>
                              <source src="' .$host. DIRECTORY_SEPARATOR  . $url'" type="video/mp4">
                            </video>' ;
              },
            'label' => 'عکس',
        ]
      ],
]);

http://www.yiiframework.com/doc-2.0/yii-helpers-html.html

http://www.yiiframework.com/doc-2.0/guide-helper-html.html