我得到: 致命錯誤:調用成員函數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);
}
哈哈哈!謝謝哈哈... –
我需要睡覺...謝謝卡斯帕爾! –