Select Betweeen on CakePHP data

1

I'm trying to select records in a date range.

$mesAtual = $this->requestAction(array('controller' => 'compras', 'action' => 'comprasMes'), array('condicoes' => array('Compra.status' => array(1,2), 'Compra.data BETWEEN ? AND ?' => array('06/30/2015', '07/30/2015')), 'ordem' => array('Compra.data_pagamento' => 'desc')));

What happens is that the records have returned but I can not sort the data: 'ordem' => array('Compra.data_pagamento' => 'desc') .

See how it is in the controller

public function comprasMes(){
    $condicoes = $this->params->params['condicoes'];
    $ordem = isset($this->params->params['ordem']) ?: null;

    $compras = $this->Compra->find('all', array( 'conditions' => array($condicoes), $ordem ));

    return $compras;
}
    
asked by anonymous 14.07.2015 / 12:20

1 answer

2

You have to pass these filters in the same array

public function comprasMes(){
    $condicoes = array(
        'conditions' => $this->params->params['condicoes'],
        'order' => isset($this->params->params['ordem'])? $this->params->params['ordem'] : array(); 
    );

    $compras = $this->Compra->find('all', $condicoes);

    return $compras;
}
    
14.07.2015 / 13:42