Cakephp多次或搜索

时间:2011-08-15 15:15:01

标签: php cakephp

我希望能够使用foreach搜索基于多个或条件的所有数据,如下所示:

 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'])));
            $count = count($commune_id);
            $i=1;
            foreach($commune_id as $commune_ids){
            if($i != $count){
            $this->paginate = array(
                'or' => array(
                    array('Petition.commune_id LIKE' => $commune_ids['Commune']['id'] . ","),
                    ),
                'limit' => 10
            );
            }
            $i++;
            }
        }
        $this->Petition->recursive = 0;
        $petitions = $this->paginate();
        $this->set('petitions', $petitions);
    }

我能够获得可能的匹配次数但是想知道我如何使用这个数组来获得具有多个条件或带有paginator函数的条件。

1 个答案:

答案 0 :(得分:0)

要在自定义情况下进行分页,通常必须覆盖Model::paginate()Model::paginateCount(),详见Custom Query pagination下的书籍。

或者,您可以使用已经实现了分页功能的插件,例如CakeDC的Search plugin