In my form, when I submit it, I send a notification email that is populated with the form inputs. One these inputs is called date
.
When I submit the form, it is submitted in the format of an array as follows:
[
'year' => 'yyyy',
'month' => 'mm',
'day' => 'dd'
]
In my controller, I then send an email to the logged in user before saving the form data to the database.
This is an excerpt of my email's ViewVars:
$email->viewVars([
'date' => $date,
]);
Because the date is in the form of an array, I get the following error in the email:
Notice (8): Array to string conversion [APP/Template\Email\html\bookingrequest.ctp, line 15]
with line 15 being the line where I do an echo of the viewVars variable $date, as follows:
<?= $date ?>
I was looking up ways of doing a conversion from array to string and have tried the following:
Given $date = $data['session']['date'];
$date = date('Y-m-d',$date->getTimestamp());
- cannot be used on an array$date = $this->Bookings->Sessions->deconstruct('date', $date);
- found out it was deprecated$date = $data['session']['date']->i18nFormat();
- cannot be used on an array