如何将视频嵌入laravel代码 [英] how to embed video in laravel code

查看:139
本文介绍了如何将视频嵌入laravel代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我将youtube视频链接存储在数据库中,然后检索这些链接,并使用刀片模板引擎尝试将它们嵌入页面中.我使用循环将视频放在页面中.由于某种原因,我在浏览器中没有收到任何视频.它覆盖了提到的空间,但未呈现任何内容.我正在使用laravel3.如果有帮助,这里有一些代码片段.

I am working on a project in which I store youtube video links in a database and then I retrieve those links and using blade template engine i try to embed them into page. I use a loop to put videos in a page. For some reason I'm not getting any video in the browser. It is covering the mentioned space but not rendering anything. I'm using laravel 3. Here's couple of code snippets, if they help.

这是index.blade.php

This is the index.blade.php

@layout('layouts.master')

@section('content')

@foreach ($videos as $video)
    <h4>{{ $video->title }}</h4>
    <br>
    <div class="media">
        <div class="media-body">
            <iframe width="560" height="315" src="{{ $video->link }}" frameborder="0" allowfullscreen>
            </iframe>
        </div>
    </div>
    <br>
@endforeach

@endsection


$ videos变量是从控制器传递的.


The $videos variable is passed from controller.

class Videos_Controller extends Base_Controller
{
public $restful = true;

public function get_index()
{
    $videos = DB::table('videos')->get();
    return View::make('videos.index')
        ->with('title', 'Videos')
        ->with('videos', $videos);
}
}


我所得到的只是一个空白页.我不明白我在做什么错.我正在使用twitter bootstrap进行CSS原型设计.任何帮助将不胜感激.


All i get is a blank page. I don't understand what i'm doing wrong. I'm using twitter bootstrap for css prototyping. Any help will be appreciated.

这是master.blade.php的头"的样子:

Here's how master.blade.php's 'head' looks like:

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ $title }} </title>
    <meta name="viewport" content="width=device-width">
    {{ HTML::style('css/bootstrap.min.css') }}
    {{ HTML::style('css/bootstrap-responsive.min.css') }}
</head>


这是我检查元素时firefox中出现的内容.


This is what comes up in firefox when I inspect element.

<div class="media">

<div class="media-body">
    <iframe width="560" height="315" frameborder="0" allowfullscreen=""   src="http://www.youtube.com/watch?v=1iBm60uJXvs">
        #document
            <html>
                <head></head>
                <body></body>
            </html>
    </iframe>
</div>

</div>

推荐答案

对于希望在Laravel中嵌入视频的其他人,请查看 KaneCohen/嵌入.它可以与Youtube或Vimeo一起使用(没有尝试其他来源),并且您不必弄乱任何逻辑.只需安装(文档中的安装指南)并:

For anyone else looking to Embed Videos in Laravel, have a look at KaneCohen/embed. It's works great with Youtube or Vimeo (haven't tried other sources), and you don't have to mess with any logic. Simply install (installation guide in documentation) and:

@foreach ($videos as $video)
    <h4>{{ $video->title }}</h4>
    <div class="media">
        <div class="media-body">
            {!! Embed::make($video->link)->parseUrl()->getIframe() !!}
        </div>
    </div>
@endforeach

别忘了在您的config/app.php

这篇关于如何将视频嵌入laravel代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆