I'm trying to add a date value to a CakePHP entity before patching it, but it doesn't work. I had to workaround by creating an array and patching it. How can I change my code to manipulate the entity object instead of patching it with an array?
Here is the current code and the code I want to use instead:
//current code
$cotacao = $this->Cotacaos->newEntity();
$dados = $this->request->getData();
$agora = Time::now();
$dados['data'] = [
'year' => $agora->year,
'month' => $agora->month,
'day' => $agora->day,
'hour' => $agora->hour,
'minute' => $agora->minute
];
$cotacao = $this->Cotacaos->patchEntity($cotacao, $dados);
if ($this->Cotacaos->save($cotacao)) {
//etcetera
//proposed code
$cotacao = $this->Cotacaos->newEntity();
$cotacao->data = Time::now();
$cotacao = $this->Cotacaos->patchEntity($cotacao, $this->request->getData());
if ($this->Cotacaos->save($cotacao)) {
//etcetera
The problem is: The date isn't being saved if I do it the second way. =(