2011-08-18 40 views
0

我得到: 致命錯誤:調用成員函數query ()的非對象在/var/www/likeslomakkeet/controllers/petitions_controller.php上線33致命錯誤:調用第33行上的/var/www/likeslomakkeet/controllers/petitions_controller.php中的非對象的成員函數query()

用下面的代碼上。我不知道爲什麼,因爲我已經在var $ name ='Petition'的模型中正確定義了$ name; 當我把自定義查詢時出現錯誤。

任何人有什麼建議嗎?

function index() { 
     if ($this->Session->read('Auth.User.group_id') != 1) { 
      $commune_id = $this->Session->read('Auth.User.commune_id'); 
      $commune_id = $this->Petition->Commune->findbyId($commune_id); 
      $commune_id = $this->Petition->Commune->find('all',array('conditions' => array('group' => $commune_id['Commune']['group']))); 
      debug($commune_id); 
      $count = count($commune_id); 
      $i=1; 
      $sql = "SELECT * FROM `petitions` WHERE `commune_id` = "; 
      foreach($commune_id as $commune_ids){ 
       if($i==1){ 
       $sql .= $commune_ids['Commune']['id']; 
       }else{ 
       $sql .= " OR `commune_id` = ".$commune_ids['Commune']['id']; 
       } 
      /*if($i != $count){ 
      $this->paginate = array(
       'or' => array(
        array('Petition.commune_id LIKE' => $commune_ids['Commune']['id'] . ","), 
        //array('Petition.commune_id LIKE' => "," . $commune_ids['Commune']['id'] . ",") 
        ), 
       'limit' => 10 
      ); 
      }*/ 
      $i++; 
      } 
      $query = $this->Petiton->query($sql); 
      debug($query); 
     } 
     $this->Petition->recursive = 0; 
     $petitions = $this->paginate(); 
     $this->set('petitions', $petitions); 
    } 

回答

0

我有一個:

$this->Petiton 
      ^^^ 

添加i

+0

哈哈哈!謝謝哈哈... –

+0

我需要睡覺...謝謝卡斯帕爾! –

2

我解決我的問題是這樣一行:

$this->loadModel('Petiton'); 
相關問題