2017-04-02 79 views
1

我嘗試使用codeigniter在我的cms項目中顯示YouTube視頻。但它不工作..我在我的MySQL數據庫中的一個表路徑中插入YouTube網址,我只是使用iframe標記下的codeigniter視圖區域調用該URL。但它沒有顯示我檢查它在瀏覽器中檢查視頻網址顯示但在標籤的下方會自動生成。任何一個可以幫助我..Codeigniter Youtube視頻不來了

這是我的看法代碼..

<div class="container"> 
     <div class="row"> 
      <?php foreach($advertisement as $ad) { ?> 
      <table> 
    <td> 
    <iframe src="<?php echo $ad->url?>" 
    width="560" height="315" frameborder="0" ></iframe> 
    </td> 
    </table> 

      <?php 
      } ?> 
    </div> 
</div> 

這是我的控制器代碼

public function advertisement(){ 
     $data['advertisement'] = $this->modelHome->populateAds(); 

     $this->load->view('layouts/head',$data);  
     $this->load->view('commercial',$data); 
     $this->load->view('layouts/footer');  
    } 

這是我的模態代碼

public function populateAds(){ 
     $this->db->select('*'); 
     $this->db->from('advertisement'); 
     $this->db->where('status','approved'); 
     $this->db->order_by('id','DESC'); 
     $query=$this->db->get(); 
     if ($query->num_rows() > 0) { 
      return $query->result(); 
     } 
    } 

這是我的表

enter image description here

+0

可以添加由該被輸出的HTML代碼?查看來源。 – versalle88

回答

1

你的代碼看起來沒問題。 問題在於數據庫中的數據。如果您查看錶中唯一的記錄,則其狀態爲批准而不是批准。並且您的型號選擇只有行狀態批准

0

在模型

public function populateAds(){ 
     $this->db->select('*'); 
     $this->db->from('advertisement'); 
     $this->db->where('status','approve'); 
     $this->db->order_by('id','DESC'); 
     $query=$this->db->get(); 
     if ($query->num_rows() > 0) { 
      return $query->result(); 
     } 
    } 
+0

我嘗試,但它不工作...在我的觀點區域你的管網址即將到來,但視頻只顯示 – pixel

+0

請使用iframe顯示視頻 –

+0

@Ramanjith我用iframe只是請檢查我的看法 – pixel