1
I’m making a query and the cake is bringing all the data ignoring $conditions. I want to search by date, but when I put a date that does not exist in any record, it still brings all the data.
public function consultarDespesa() {
if ($this->request->is('post')) {
$dataDespesa=null;
$dataDespesa = $this->request->data['Despesa']['ano']."-".$this->request->data['Despesa']['mes'];
$despesas = $this->Despesa->find('all', array(
'conditions'=>array(
'data_despesa like'=>"%$this->dataDespesa%")));
if (($despesas==null) || (!isset($despesas))) {
$this->Session->setFlash("Sua pesquisa não retornou nenhum resultado.");
}
else {
$this->Session->write("Despesas", $despesas);
$this->redirect(array('action'=>'exibirDespesas'));
}
}
}
True, but it depends on how the date is recorded in the bank.
– bfavaretto
@Jeferson Assis I’m using like because I just want to take as argument the month and the year, the day does not interest me. The like works, because I did with query and only brought when found. And in the conversion of cake, is ignoring the operator, bringing everything as if it were a select *
– André Nascimento
I changed the answer and put a complement, try the second way
– Jeferson Assis
@Andrénascimento This date is in your database as
DATETIME
orVARCHAR
?– bfavaretto
!Jeferson Assis worked!
– André Nascimento