2014-02-13 77 views
1

我的控制器是顯示圖像笨

if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class pickoftheday_display extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->library('session'); 
     //$this->load->library('upload'); 
     //$this->load->library('form_validation'); 
     $this->load->helper('url'); 
     $this->load->model('pickoftheday_display_model','',TRUE); 
     $this->pickoftheday_display_model->get_pickoftheday_image(); 
     $this->load->database(); 
    } 
    public function index() 
    { 
       $this->load->view('pickoftheday_display'); 


    } 

    public function get_pickoftheday_image() 
    { 
     $data['get_pick_picture']=$this->pickoftheday_display_model->get_pickoftheday_image(); 
    } 
} 

模型

class pickoftheday_display_model extends CI_Model 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->database(); 
     $this->load->library('encrypt'); 
     $this->load->helper('security'); 
     $this->load->helper('string'); 
     $this->load->library('email'); 
    } 

    public function get_pickoftheday_image() 
    { 
     $query=$this->db->query("SELECT * FROM pick_of_the_day order by id desc "); 
     if($query->num_rows>0) 
     { 
      return $query->result(); 

     } 
     else 
     { 

      return false; 
     } 
    } 
} 

視圖代碼是

$val=array(); 
    $link=array(); 
    var_dump($get_pick_picture); 
    foreach($get_pick_picture as $key) 
    { 
     $val[]= $key->image; 
     $link[]= $key->link; 
    } 
echo $link[0] 

如何顯示在取景圖像..

+0

什麼是你現在所得到的輸出? –

+0

是什麼問題? –

+0

甲PHP錯誤遇到 嚴重性:注意 消息:未定義變量:get_pick_picture 文件名:視圖/ pickoftheday_display.php –

回答

2
  1. 您沒有將數據傳遞給查看文件。
  2. 您沒有設置數據傳遞到查看文件。

在索引功能,你必須調用

public function index() 
{ 
    $data['pick_picture']=$this->pickoftheday_model->get_pickoftheday_image(); 
    $this->load->view('pickoftheday_display',$data); 
} 
+1

高超.. thankk你@kumar_v –