I have a problem when I want to use these 3 things together. I give this error.
The expected argument of type "AppBundle \ Entity \ Images", "array" specified
I think my form gives an array, and I don't know how to solve this problem.
This is my config.yml
form:
fields:
- 'name'
- { property: 'images', type: 'collection' , type_options: { entry_type: 'AppBundle\Form\ProductImageType', by_reference: false } }
- { property: 'date', type: 'integer', format: '%d' }
- { property: 'description', type: 'ckeditor' }
- { property: 'long_description', type: 'ckeditor' }
And the form:
class ProductImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('image', VichImageType::class, array(
'required' => true,
'allow_delete' => true,
'by_reference' => false
))
;
}
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => '\AppBundle\Entity\Images',
));
}
}
The essence of the product (this is only part of this):
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
class Product
{
protected $images;
public function __construct()
{
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addImage(Images $image){
$this->images[] = $image;
$image->setProduct($this);
return $this;
}
}
I don’t know what happened there. This array is as follows:
Form ->submit (array('name' => 'gh', 'date' => '2012', 'description' => '<p>ghgh</p> ', 'long_description' => '<p>ghgh</p> ', '_token' => 'GCVXd4ASZpdoOakbu1cfMLkTBQN0-sy1kNql4inYPTw', 'images' => array(array('image' => array('file' => object(UploadedFile))))), true)