M
M
Main2017-06-04 12:09:20
Yii
Main, 2017-06-04 12:09:20

How to properly display the path to the video from the database?

There is a video table and it also has a video field, in which I want to store the paths to my video
. And then, I want to remove this path from the database and immediately throw it into the video. Here's what I'm doing:
model

<?php
namespace frontend\models;
use yii\db\ActiveRecord;
//use yii\web\IdentityInterface;

class Video extends ActiveRecord{
  public static function tableName(){
    return 'video';
  }
  
}

SiteController
public function actionVideo()
  {
    $video = Video::find()->select('id, video');
        return $this->render('video', compact('video'));
  }

view
<div class="panel-body">
    <video width="100%" height="auto" preload="auto" autoplay="autoplay"
    loop="loop" poster="bg/daisy-stock-poster.jpg">
        <source src="<?=$video?>" type="video/mp4"></source>
    </video>
  </div>

and of course nothing works.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-06-04
@Maxmil

We change this:

$video = Video::find()->select('id, video')->all();
return $this->render('video', compact('video'));

on this
$video = Video::find()->select('id, video')->all();
return $this->render('video', ['video'=>$video]);

In the view, we iterate over an array of objects, and not like you <?=$video?>accessed it as a string
<?php foreach($video as $one): ?>
<div class="panel-body">
    <video width="100%" height="auto" preload="auto" autoplay="autoplay"
    loop="loop" poster="bg/daisy-stock-poster.jpg">
        <source src="<?=$one->video?>" type="video/mp4"></source>
    </video>
  </div>
<?php endforeach; ?>

D
Dmitry, 2017-06-04
@slo_nik

Good afternoon.
For the value of the src attribute, use Url::to()
Let's say the files are in web/uploads/video/name_file.mp4
Try this

<source src="<?= Url::to('@web/uploads/video/' . $video) ?>"></source>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question