Reputation: 6042
I have an entity of type Blah
with the following fields:
/**
* @var datetime $begin
*
* @ORM\Column(name="begin", type="datetime", nullable=true)
*/
private $begin;
/**
* @var datetime $end
*
* @ORM\Column(name="end", type="datetime", nullable=true)
*/
private $end;
With the following getters/setters:
/**
* @param $begin
*/
public function setBegin($begin)
{
$this->begin = $begin;
}
/**
* @return \DateTime
*/
public function getBegin()
{
return $this->begin;
}
/**
* @param $end
*/
public function setEnd($end)
{
if ($end < $this->begin) {
$this->end = $this->begin->add(\DateInterval::createFromDateString('1 day'));
} else {
$this->end = $end;
}
}
/**
* @return \DateTime
*/
public function getEnd()
{
return $this->end;
}
And a corresponding form type that has:
$builder->add('begin', 'datetime', array(
'label' => 'Begin',
'required' => false,
));
$builder->add('end', 'datetime', array(
'label' => 'End',
'required' => false,
));
And the form handling portion of the method in question:
$form = $this->createForm(new BlahType(), $blah);
if ($request->getMethod() == 'POST') {
$postData = $request->request->all();
if (!empty($postData['save'])) {
$form->handleRequest($request);
$numThings = $postData['blah']['numThings'];
if ($numThings) {
for ($i = 0; $i < $numThings; ++$i) {
$thing = new Thing();
$blah->addThing($thing);
}
}
$em->persist($blah);
$em->flush();
}
}
When I attempt to save these entries, null
gets passed back to the entity despite the fact that the populated entity contains two arrays for each entry
Screen shot of what's passed back to the entity:
Screen shot of what the populated entity supposedly has after $form->handleRequest()
:
Needless to say, I'm confused. According to the docs, a datetime
field should default to having an input
of, well, datetime
, yet I'm getting the data back as a series of two arrays per field - one array with the day, month, and year, and the other with the hour and minutes. And even with that, null
is what's being passed back to the entity and persisted in the db.
It's baffling. Any suggestions/answers?
EDIT: The form itself has null
s in its viewData
:
Upvotes: 0
Views: 302
Reputation: 6042
Figured it out. Problem was due to PHP inexplicably only recognizing Continent/City timezones instead of the old Country/Timezone timezones. US/Eastern is no longer valid.
Upvotes: 0