I created a new field type and I am trying to use it in sonata. In one of my admin classes I have the following:
$formMapper
->add('name', 'text')
->add('img_home', new \MyBundle\Form\Type\ImageType(), array(
'required' => false,
'mapped' => false,
'label' => 'home set image',
'attr' => array('src' => '/' . $home)
)
)
When I do this on the img_home field I trigger this exception
'Please define a type for field ...'
If I comment out this exception everything works fine. I see the field I want without any issues.
How can I fix this without having to change the code?
Found the solution. After reading the code I noticed that there is a 4th argument you can pass and sonatas code checks if the array passed has they 'type' key. So I just added :
array('type' => 'string')
As the 4th parameter
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.