2014-02-19 56 views
0

在運行笨我有以下錯誤:

A PHP Error was encountered Severity: Notice Message: Undefined property: Social::$social_model Filename: controllers/social.php Line Number: 10

請告訴我請問我的代碼有什麼幫助嗎?

controllers/social.php

class Social extends CI_Controller { 

    public function index(){ 

      $data = array(); 
      $this->load->view('header.php'); 
      $this->load->view('staffs/content.php'); 
      if ($query = $this-> social_model -> get_records()) // **[line 10]** 
      { 
       $data['records'] = $query; 
      } 

      $this->load->view('social/content.php', $data); 
      $this->load->view('footer.php'); 
     } 

    // .... 
} 

models/social_model.php

<?php 
class social_model extends CI_Model{ 

    function get_records() 
    { 
     $query = $this->db->get('admins'); 
     return $query -> result(); 
    } 

    // .... 
} 
+0

應該是'如果($查詢== $ this' –

+0

我嘗試過,但它還沒有工作:( –

+2

您的代碼並不顯示社會和Si之間的任何關係te_model。事實上,你是指它在社會social_model,但你永遠不任何實例作爲這個 - $> social_model。如果你不聲明參數social_model,那麼你就不能使用它。 –

回答

1

必須加載模型:

$this->load->model('social_model'); 
+0

歡迎來到[so]。雖然這解決了OP的問題,但一個好的答案不止於此。描述問題中提到的通知的原因,解釋您建議的代碼更改如何解決問題。 – axiac

相關問題