致命错误:在第33行的/var/www/likeslomakkeet/controllers/petitions_controller.php中调用非对象的成员函数query()

时间:2011-08-18 13:15:19

标签: php cakephp

我得到了: 致命错误:在第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);
    }

2 个答案:

答案 0 :(得分:2)

我解决了我的问题就像这一行:

$this->loadModel('Petiton');

答案 1 :(得分:0)

我有一个:

$this->Petiton
          ^^^

添加i