我想创建一个 html 选择字段,其中包含上次编辑的日期时间条目。当采用数据库中的任何其他字段时,这有效,而日期时间则无效。
在我的表单类型中
class MemberlistType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('CreatedAt', 'entity', array(
'mapped' => false,
'class' => 'TestProject\TestBundle\Entity\Memberlist',
'property' => 'created_at'
))
`
在我看来
{{form_label(form.children.memberlists[0].children.CreatedAt}}
{{form_widget(form.children.memberlists[0].children.CreatedAt}}
{{form_errors(form.children.memberlists[0].children.CreatedAt)}}
我得到:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object
of class DateTime could not be converted to string in /var/www/symfony/vendor/symfony/symfony
/src/Symfony/Component/Translation/Translator.php line 188") in
TestprojectTestBundle:Default:updateData.html.twig at line 77
如何以简单的方式将此日期时间转换为字符串?