2013-04-06 46 views
-1

我整合Vimeo的球員與我的CakePHP的應用及其給我上面的錯誤一個非對象調用一個成員函數getEmbedHtml()

Error: Call to a member function getEmbedHtml() on a non-object 
File: C:\wamp\www\ann\app\View\Videos\index.ctp 
Line: 1 

,這裏是我的第1行

<?php echo $vimeo->getEmbedHtml('https://www.vimeo.com/44633289', array()); ?> 

此鏈接工作https://www.vimeo.com/44633289

這裏是Vimeohelper.php文件

<?php 
class VimeoHelper extends AppHelper 
{ 
    /** 
    * Creates Vimeo Embed Code from a given Vimeo Video. 
    * 
    * @param String $vimeo_id URL or ID of Video on Vimeo.com 
    * @param Array $usr_options VimeoHelper Options Array (see below) 
    * @return String HTML output. 
    */ 
    function getEmbedCode($vimeo_id, $usr_options = array()) 
    { 
     // Default options. 
     $options = array 
     ( 
      'width' => 400, 
      'height' => 225, 
      'show_title' => 1, 
      'show_byline' => 1, 
      'show_portrait' => 0, 
      'color' => '00adef', 
     ); 
     $options = array_merge($options, $usr_options); 

     // Extract Vimeo.id from URL. 
     if (substr($vimeo_id, 0, 21) == 'http://www.vimeo.com/') { 
      $vimeo_id = substr($vimeo_id, 21); 
     } 

     $output = array(); 
     $output[] = sprintf('<object width="%s" height="%s">', $options['width'], $options['height']); 
     $output[] = ' <param name="allowfullscreen" value="true" />'; 
     $output[] = ' <param name="allowscriptaccess" value="always" />'; 
     $output[] = sprintf(' <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=%s&server=www.vimeo.com&show_title=%s&show_byline=%s&show_portrait=%s&color=%s&fullscreen=1" />', $vimeo_id, $options['show_title'], $options['show_byline'], $options['show_portrait'], $options['color']); 
     $output[] = sprintf(' <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=%s&server=www.vimeo.com&show_title=%s&show_byline=%s&show_portrait=%s&color=%s&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="%s" height="%s"></embed>', $vimeo_id, $options['show_title'], $options['show_byline'], $options['show_portrait'], $options['color'], $options['width'], $options['height']); 
     $output[] = '</object>'; 

     return $this->output(implode($output, "\n")); 
    } 
} 
?> 

回答

0

你能提供更多關於如何初始化$ vimeo的信息嗎?

很可能$ vimeo初始化不正確,並且在您訪問它時設置爲null。 希望這有助於您的調試。

此外,它看起來像VimeoHelper中的getEmbedCode函數是您想要使用,而不是getEmbedHtml。

考慮改變函數定義是

static function getEmbedCode($vimeo_id, $usr_options = array()) 

,那麼你可以通過調用後得到嵌入的URL:

VimeoHelper::getEmbedCode('https://www.vimeo.com/44633289', array()) 
+0

我在問題的上述部分添加了Vimeohelper.php,請檢查。 – 2013-04-06 10:33:09

+0

Vimeohelper.php不包含初始化第一個示例中的$ vimeo變量的代碼。 – 2013-04-06 10:39:39

1

錯誤告訴你,你需要知道的一切。 您沒有正確訪問幫助程序。

一),你需要把它列入你的控制器public $helpers

b)您需要正確地調用它使用$this-Vimeo和正確的方法名(你不能只是創造你自己的名字,因爲該方法需要存在!) :

<?php echo $this-Vimeo->getEmbedCode(...); ?> 

$vimeo->您的代碼段將是完全的過時cake1.2(不適用於cake1.3或cake2.x)是正確的。

+0

public $ helpers = array('Vimeo');用於控制器 <?php echo $ this-> Vimeo-> getEmbedHtml('https://www.vimeo.com/44633289',array()); ?>在index.ctp ,現在它給我的警告 警告(512):該方法VimeoHelper :: getEmbedHtml不存在[CORE \蛋糕\查看\ Helper.php,線191] – 2013-04-06 10:58:14

+0

你爲什麼發明了方法這裏的名字?你的助手清楚地說明該方法被稱爲'getEmbedCode()'。 – mark 2013-04-06 11:02:11

+0

嗨,感謝它的工作,但仍然沒有顯示視頻,而不是外部部分顯示與內部消息 對不起這個視頻不存在 – 2013-04-06 11:07:34

相關問題