简体   繁体   English

如何在编辑时设置奏鸣曲形式data_class

[英]how to set sonata form data_class on edit

im stuck with following error message on a project with symfony 2.8 and sonata admin/media bundle. 我在使用symfony 2.8和奏鸣曲admin / media捆绑包的项目中遇到以下错误消息。 i log in sonata and navigate to the list view were i have an edit button. 我登录奏鸣曲并导航到列表视图,如果我有一个编辑按钮。 i click the edit button and get following error. 我单击编辑按钮,并得到以下错误。

error message: The form's view data is expected to be of type scalar, array or an instance of \\ArrayAccess, but is an instance of class DateTime. 错误消息:窗体的视图数据应为标量类型,数组或\\ ArrayAccess的实例,但为DateTime类的实例。 You can avoid this error by setting the "data_class" option to "DateTime" or by adding a view transformer that transforms an instance of class DateTime to scalar, array or an instance of \\ArrayAccess. 您可以通过将“ data_class”选项设置为“ DateTime”或添加一个将视图类DateTime的实例转换为标量,数组或\\ ArrayAccess实例的视图转换器来避免此错误。

i found some answers via stackoverflow saying that the data_class needs to be set on the specific formtype. 我通过stackoverflow找到了一些答案,说data_class需要在特定的表单类型上设置。 but thats sonata, were can i find the form i have to work on? 但是那是奏鸣曲, 我能找到我要处理的表格吗?

You can describe it in your admin class 您可以在管理类中对其进行描述

protected function configureFormFields(FormMapper $form)
{
    $form->add('date', 'datetime', array('data_class' => 'DateTime'));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM