简体   繁体   中英

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. 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. 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.

i found some answers via stackoverflow saying that the data_class needs to be set on the specific formtype. 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'));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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