/**
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="mKeyword")
* @ORM\Entity(repositoryClass="KeywordRepository")
*/
class Keyword {
/**
* @ORM\OneToOne(targetEntity="Image",mappedBy="keyword" ,cascade={"all"})
* @var Image
*/
private $logo;
}
/**
* @Vich\Uploadable
* @ORM\Entity
* @ORM\Table(name="mKeywordLogo")
*/
class Image {
}
form
class KeywordType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title','text')
->add('logo',new ImageType())
image form
class ImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('file','vich_image',array(
'label'=>'logo'
));
}
when save form get
Expected value of type "KeywordsBundle\Entity\Image" for association field "Mea\KeywordsBundle\Entity\Keyword#$logo", got "array" instead.
i add array parser in Keyword
public function setLogo($logo)
{
if(is_array($logo))
$logo = reset($logo);
$this->logo = $logo;
}
so get error
Expected value of type "KeywordsBundle\Entity\Image" for association field "KeywordsBundle\Entity\Keyword#$logo", got "Symfony\Component\HttpFoundation\File\UploadedFile" instead.