php - CakePHP Form Helper and Datetime
372
I have used the form helper to create a date time selection and when I access the$this->data
.
It looks like the following.
[Timetable] => Array
(
[event_id] => 133
[location_id] => 39
[start] => Array
(
[hour] => 09
[min] => 06
[day] => 11
[month] => 03
[year] => 2011
)
)
But I want this to look more like this...
[Timetable] => Array
(
[event_id] => 133
[location_id] => 39
[start] => 2011-03-11 09:06:00
)
Is there a way to transform it to this?
Answer
Solution:
You can just rebuild the
$this->data['Timetable']['start']
var in your controller like so:Should work fine.
Answer
Solution:
This is undocumented in the Cookbook, but the function the model uses to convert that array into a database-friendly format is
. You can use it as follows:
This solution has the benefit of not breaking the MVC abstraction by having your controller know anything about the structure of data submitted by a form or how the database stores it.
Answer
Solution:
Since you're using the form helper to generate your code, you can't get it into a single index unless you change your form helper.
You're probably using
Changing it to the below will make it come out the way you want.
However, if you do this, you'll lose out on all the dropdowns that cake auto generates for you. Not a problem if you use a datepicker.