Select Betweeen in data Cakephp

Asked

Viewed 105 times

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’t 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;
}

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;
}
  • Thanks. It worked out here!!

Browser other questions tagged

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