I want to be able to search all data based on multiple or conditions using foreach like below:
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);
}
I was able to get possible number of matches but was wondering how I can use this array to get results with multiple or conditions with paginator function.
To do pagination in custom situations like this, one normally has to override
Model::paginate()andModel::paginateCount()as detailed in the book under Custom Query pagination.Alternatively, you could use a plugin that already has features such as pagination implemented, such as CakeDC’s Search plugin.