2013-05-03 156 views
-1

我完全不熟悉PHP和CodeIgniter,我試圖在視圖中創建一個鏈接,點擊後將返回一個特定類別的數據列表。CodeIgniter鏈接到搜索

vgs_model.php模型

public function pcList(){ 

    $this->db->select('*'); 
    $this->db->from('videogame'); 
    $this->db->where('Format', 'PC'); 
    $query = $this->db->get(); 

    return $query->result(); 

} 

的search.php控制器

public function __construct() 
{ 
    parent::__construct(); 

    $this->load->helper('form'); 
    $this->load->helper('url');  
    $this->load->model('vgs_model'); 

} 

public function index() 
{ 
    $this->load->view('header_view'); 
    $this->load->view('search_view'); 
    $this->load->view('footer_view'); 
} 

public function getPc(){ 

    $search_term = 'PC'; 

    $data['results'] = $this->Vgs_model->pcList(); 
    $this->load->view('search_results', $data); 

} 

search_view查看

<a href = <?php echo site_url('Hello/getPc'); ?>>View PC Games</a> 

我已經收到以下錯誤

Message: Undefined property: Search::$Vgs_model 

Filename: controllers/search.php 

Line Number: 40 

第40行是這樣的 $data['results'] = $this->Vgs_model->pcList();

我在做什麼錯?任何幫助,將不勝感激。

感謝您閱讀我的文章。

回答

1

這是前人的精力用小寫:

$data['results'] = $this->vgs_model->pcList(); 
+0

噢,我的上帝,是熱鬧!這樣一個簡單的錯誤。我喜歡用文本編輯器進行編程。非常感謝你查理。 – 2013-05-03 02:01:45

+0

是的,我也使用文本編輯器進行編程,很高興可以幫助:) – egig 2013-05-03 02:04:06

+0

實際上,根據CI慣例,您的模型加載應該是'$ this-> load-> model('Vgs_model');'型號名稱是大寫。以上內容將保持大寫,除非您在加載時指定第二個參數以不同地命名。請參閱http://ellislab.com/codeigniter/user-guide/general/models.html,但這只是堅持CI的方式,您應該使用這種方式,因爲它可能會在後面的版本中產生意想不到的副作用。 – 2013-05-03 09:08:17