callback afterFind

1

Hello, I still can not use afterFind, even following a few posts on the net. Help me in the controller and model, please. I use beforeSave, but I can not use afterFind.

I have already put return false or true in the controller method, but it did not work.

Does anyone have any functional code with afterFind to send me?

controller Expenses

link

AppModel

link

Model Expense

link

    
asked by anonymous 05.01.2016 / 14:51

2 answers

1

By analyzing your code I saw that you use the query() method of the model.

$despesas=$this->Despesa->query("select * from despesas where data_despesa like '%$this->dataDespesa%'");

When you use a custom query, it does not automatically go to afterFind()

You can call it in sequence:

$despesas = $this->Despesa->afterFind($this->Despesa->query("select * from despesas where data_despesa like '%$this->dataDespesa%'"));

Because your query is simple you do not need to do a custom query

Just use the method find()

$despesas = $this->Despesa->find('all', array(
    'conditions'=>array(
        'data_despesa like'=>"%{$this->dataDespesa}%"
    )
));

So it will automatically go through all the callbacks.

    
18.01.2016 / 13:57
0

I've solved it. The problem is that I was using the same methods to format date and the monetary value of the beforeSave. Or beforeSave replaces "/" with "-" and places it in the format y, m, d. And replace "," with "." in monetary value.

To display in the view, you had to do the opposite: put the date in the format d, m, y and replace "-" with "/". And in monetary value, replace "." per ",".

AppModel

link

Model Expense

link

controller Expenses

link

    
19.01.2016 / 14:25