0

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()"
Saltern
  • 1,305
  • 2
  • 16
  • 42
  • there is not an Video() function is HtmlHelper http://www.yiiframework.com/doc-2.0/yii-helpers-html.html .. you should wraute flat html code – ScaisEdge Sep 16 '17 at 11:18
  • This might help you https://stackoverflow.com/questions/32859125/how-to-render-youtube-video-in-yii2-detailview-widget – Bira Sep 19 '17 at 07:22

1 Answers1

0

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

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • answer updated .. (missing $url) but check for real $path .. real complete url and your real video type .. mine is suggestion – ScaisEdge Sep 16 '17 at 11:39
  • return ''; again td is blank ! video tag is not in td tag! ;-( link is correct with this :"$host/" . $url – Saltern Sep 16 '17 at 11:47
  • I think @scaisEdge make an error in the code: look the first line, before height="240" there is "<", try to remove it like this: – Gabriele Carbonai Sep 16 '17 at 11:58
  • anyway i have updated the answer with a code for DetailView widget .. and remember that the anonymous function for detailView work starting from version 2.0.11 – ScaisEdge Sep 16 '17 at 15:13