Search query in cakephp

Asked

Viewed 294 times

1

I want to do a query that finds the date, but the query below is finding even when I do not pass value or when it is a value that has nothing to do with date:

$busca = $this->Despesa->find('all', array('data_despesa' => '2'));

In this query there was not to return anything. But it is bringing everything, as if it were a select * from nomeDaTabela.

What’s wrong with it?

I’m wanting to do sql outside the framework standard, how would it be? I’ve seen that it’s something like this: $this->query("codigo dml");

1 answer

3


What happens is that you got the values of the second parameter wrong. The method find() wait as second parameter one array with one or more of the following keys: 'conditions', 'limit', 'recursive', 'page', 'Fields', 'offset', 'order', 'callbacks'.

To use conditions as you intend, you must use the key conditions, which is a array, thus:

$busca = $this->Despesa->find('all', array('conditions' => array('data_despesa' => '2015-10-21')));

For the second doubt, with the method query() you can write all your sentence, pure SQL, without using the model of Cakephp.

Browser other questions tagged

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