1
/**
* @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 {
}
class KeywordType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title','text')
->add('logo',new ImageType())
圖像形式
class ImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('file','vich_image',array(
'label'=>'logo'
));
}
時節省形式 得到
Expected value of type "KeywordsBundle\Entity\Image" for association field "Mea\KeywordsBundle\Entity\Keyword#$logo", got "array" instead.
i的關鍵詞
添加陣列解析器public function setLogo($logo)
{
if(is_array($logo))
$logo = reset($logo);
$this->logo = $logo;
}
所以得到錯誤
預計的關聯域 「KeywordsBundle \實體\關鍵字#$標識」 類型 「KeywordsBundle \實體\意象」,得到了價值 「的Symfony \分量\ HttpFoundation \文件\ UploadedFile的」代替。