I have an Entity named Task and build a Symfony TaskType.php for the form.
It is my aim to set the endDate datetime field by default to the input of the startDate datime field (which is required).
I tried this, but it doesn't work.
$builder->add('name');
$builder->add('startDate', 'datetime');
$builder->add('endDate', 'datetime', array(
'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'),
'required' => false,
'data' => isset($options['data']) ? $options['data']->getEndDate() : $options['data']->getStartDate(),
));
Exception:
An exception occurred while executing 'INSERT INTO Task (name, startDate, endDate) VALUES (?, ?, ?)' with params {"1":"test","2":"2013-03-30 00:00:00","3":null}:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'endDate' cannot be null
500 Internal Server Error - DBALException
1 linked Exception:
PDOException ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…