【问题标题】:Cakephp multiple or searchCakephp 多个或搜索
【发布时间】:2011-08-15 23:36:12
【问题描述】:

我希望能够使用如下 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);
    }

我能够获得可能的匹配数,但想知道如何使用这个数组来获得具有多个或条件的结果与分页器功能。

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    要在这样的自定义情况下进行分页,通常必须覆盖Model::paginate()Model::paginateCount(),如本书Custom Query pagination 下的详细说明。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多