2016-01-18 105 views
3

我是新來的蛋糕PHP,我CakePHP安裝視頻輔助,主助手插件嵌入視頻,在我的引導文件我自動加載該插件這樣Plugin::load('VideoEmbed', ['autoload' => true]);視頻嵌入問題蛋糕PHP 3.0

我的視圖文件包括行:

echo $this->Video->embed($video['Video']['https://www.youtube.com/embed/ms7M8q1UTVk']);` 

它顯示視頻未定義爲錯誤。

錯誤屏幕:

error screen

查看

view file

+0

順便說一句:還有https://github.com/dereuromark/MediaEmbed – mark

回答

1

docs

// Usage 
echo $this->Video->embed($video['Video']['url'], array(
    'width' => 450, 
    'height' => 300, 
    'failSilently' => true // Disables warning text when URL is not recognised 
)); 

這應該工作:

echo $this->Video->embed('https://www.youtube.com/embed/ms7M8q1UTVk'); 
+0

正確的答案,但對於錯誤的插件!您鏈接到的插件是用於CakePHP 2的,OP引用的插件大多數可能是[VideoEmbed](https://github.com/drmonkeyninja/cakephp-video-helper),CakePHP 2和3. – drmonkeyninja

+1

@drmonkeyninja:更新了答案。順便說一句,好的工作! :) –

2

VideoEmbed第一個參數是該視頻的網址(一string)。所以,你的呼叫需要看起來像: -

echo $this->Video->embed('https://www.youtube.com/embed/ms7M8q1UTVk'); 

根據你的錯誤消息$video甚至還沒有確定,所以你實際上並沒有經過什麼輔助方法。確保您的控制器中設置了$video變量,並且您通過embed方法的數組值爲string URL。你可能希望做類似: -

if (!empty($video['Video']['url'])) { 
    echo $this->Video->embed($video['Video']['url']); 
}