Cakephp 2.x: Custom Query Paging

Asked

Viewed 208 times

1

I’ve hit my head a lot so far to try to understand how Cakephp pagination works with Custom Query’s but haven’t had much success. This is the method I currently have, I want to make a pagination on top of it, how to use the Paginator in that situation?

    function search(){
    $this->layout = 'mpf';
    $fields = array('Convenio.*','tbl_agencias.gerev');
    $join = array(  
        array(
            'table' => 'tbl_agencias',
                'type' => 'LEFT',
                'conditions' => array('Convenio.centralizadora = tbl_agencias.id')
        )
    );
    $conditions = array(
        'OR' => array(
            'Convenio.nome LIKE' => "%".$this->request->data['Convenio']['search']."%",
            'Convenio.centralizadora' => $this->request->data['Convenio']['search'],
            'Convenio.id' => $this->request->data['Convenio']['search'],
        ),
        array(
            'AND' => array(
                'Convenio.situacao != ' => '-1'
            )
        )
    );
    $group = array('Convenio.nome');
    $this->set('convenios', $this->Convenio->find('all',array('fields'=>$fields,'conditions'=>$conditions,'joins'=>$join,'group'=>$group)));
}

2 answers

0

0


I guess it was just a lack of interpretation. It was enough to pass the parameters as if it were in the find()

Stayed like this:

   function search(){
        $this->layout = 'mpf';
        $fields = array('Convenio.*','tbl_agencias.gerev');
        $join = array(  
            array(
                'table' => 'tbl_agencias',
                    'type' => 'LEFT',
                    'conditions' => array('Convenio.centralizadora = tbl_agencias.id')
            )
        );
        $conditions = array(
            'OR' => array(
                'Convenio.nome LIKE' => "%".$this->request->data['Convenio']['search']."%",
                'Convenio.centralizadora' => $this->request->data['Convenio']['search'],
                'Convenio.id' => $this->request->data['Convenio']['search'],
            ),
            array(
                'AND' => array(
                    'Convenio.situacao != ' => '-1'
                )
            )
        );
        $group = array('Convenio.nome');
        $this->Paginator->settings = array(
            'conditions' => $conditions,
            'fields' => $fields,
            'joins' => $join,
            'group' => $group,
            'limit' => 25
        );
        $convenios = $this->Paginator->paginate('Convenio');
        $this->set(compact('convenios'));
        //$this->set('convenios', $this->Convenio->find('all',array('fields'=>$fields,'conditions'=>$conditions,'joins'=>$join,'group'=>$group)));
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.