当我想要将这3件事物放在一起时,我遇到了一些问题。我给出了这个错误。
类型" AppBundle \ Entity \ Images"," array"的预期参数给定
我认为我的表单有一个数组,我不知道如何解决这个问题。
这是我的config.yml
form:
fields:
- 'name'
#- { property: 'image', type: 'vich_image' } #, type_options: { multiple: true, label: 'Image', data_class: null } }
- { 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' }
表格:
class ProductImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('image', VichImageType::class, array(
'required' => true,
//'mapped' => 'product',
'allow_delete' => true,
'by_reference' => false
))
;
}
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => '\AppBundle\Entity\Images',
));
}
}
产品实体(它只是其中的一部分):
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Images", mappedBy="product", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $images;
/**
* Constructor.
*/
public function __construct()
{
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add images
*
* @param \AppBundle\Entity\Images $image
*
* @return Product
*/
public function addImage(Images $image){
$this->images[] = $image;
$image->setProduct($this);
return $this;
}
}
我不知道那里发生了什么。给定的数组如下所示:
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)