1
I have two rules in two camps.
In the data_expense field, I want to take the format d/m/a
and move on to a-m-d
. Turns out when you save it on the bench, it’s like 0000-00-00
. I don’t know how to debug the model to see how it is transforming and the controller, when debugging the $this->request->data
) does not use validation.
The field valor_despesa
is ok. You are changing from "," to ".". The problem is only in formatting data_despesa
.
What’s wrong with it?
Follow the model code:
<?php
class Despesa extends AppModel {
public $name='despesa';
public $useTable='despesas';
public $primaryKey='id_despesa';
public $validate=array(
'data_despesa'=>array(
'data'=>array(
'rule'=>array('data'))),
'valor_despesa'=>array(
'preco'=>array(
'rule'=>array('preco'))));
public function data($check) {
$dataDespesa=explode("/", $check['data_despesa']);
$dataDaDespesa="";
$dataDaDespesa=$dataDespesa[2]."-".$dataDespesa[1]."-".$dataDespesa[0];
return true;
}
public function preco($check) {
$valorDespesa=str_replace(",", ".", $check['valor_despesa']);
return true;
}
}
?>
Use
<pre><code>
to format the question, the prettify of the site does not work: http://answall.com/editing-help– brasofilo
the field
data_despesa
is with the guydate
in the Database? If yes, the formatyyyy-MM-dd
is the default format of the 'date' fields. What you can do is model this value to show on the screen, but the date fields will always save in this format in the Database. If it were possible to save anyway, the Database would have problems comparing two dates.– dnr1
@Dennne what I want is to change from d/m/a to y-m-d I got in the controller, but in the model, I can’t. It was a wonder this validation in the controller, so I want to implement in the model.
– André Nascimento