2017-08-31 1 views
0

私は3つのエンティティPost CarousselCarousselImgを持っています。 Carouselエンティティは、post_id およびCarousselImgエンティティを持つポストエンティティに関連していますか?caroussel_idのCarousselエンティティに関連しています。 多対1および多対1の関係は、教義によって生成されます。フォームコレクション内のフォームコレクションSymfony

問題は、カルーセル[carousselimgを含む]を含む投稿を追加しようとするときです。クラス

プロパティ「carousselImgs」は「AppBundle \エンティティ\ Carousselを」方法で定義することができる「addCarousselImg()」、「removeCarousselImg()」が、新しい値は、配列またはインスタンスでなければならない\ Traversable、 "AppBundle \ Entity \ CarousselImg"を指定します。

ここでここでポストタイプ

->add('caroussels',CollectionType::class, array(
       'entry_type' => CarousselType::class, 
       'allow_add' => true, 
       'delete_empty'=>true, 
       'by_reference' => false, 
       'prototype' => true, 
       'entry_options' => array(
        'attr'  => array('class' => 'caroussels-box') 
       ), 
      ) 
     ) 

の私Carousselを部分は私のcarousselImg部分がCarousselをタイプに助け

<?php 
 

 
namespace AppBundle\Entity; 
 

 
use Doctrine\ORM\Mapping as ORM; 
 

 
/** 
 
* CarousselImg 
 
* 
 
* @ORM\Table(name="caroussel_img") 
 
* @ORM\Entity(repositoryClass="AppBundle\Repository\CarousselImgRepository") 
 
*/ 
 
class CarousselImg 
 
{ 
 
    /** 
 
    * @var int 
 
    * 
 
    * @ORM\Column(name="id", type="integer") 
 
    * @ORM\Id 
 
    * @ORM\GeneratedValue(strategy="AUTO") 
 
    */ 
 
    private $id; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="imgUrl", type="string", length=255) 
 
    */ 
 
    private $imgUrl; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="description", type="text", nullable=true) 
 
    */ 
 
    private $description; 
 

 

 
    /** 
 
    * @ORM\ManyToOne(targetEntity="Caroussel", inversedBy="carousselImgs") 
 
    * @ORM\JoinColumn(name="caroussel_id", referencedColumnName="id") 
 
    */ 
 

 
    private $caroussel; 
 
    public function __toString() 
 
    { 
 
     return $this->id; 
 
    } 
 
    /** 
 
    * Get id 
 
    * 
 
    * @return integer 
 
    */ 
 
    public function getId() 
 
    { 
 
     return $this->id; 
 
    } 
 

 
    /** 
 
    * Set imgUrl 
 
    * 
 
    * @param string $imgUrl 
 
    * @return CarousselImg 
 
    */ 
 
    public function setImgUrl($imgUrl) 
 
    { 
 
     $this->imgUrl = $imgUrl; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get imgUrl 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getImgUrl() 
 
    { 
 
     return $this->imgUrl; 
 
    } 
 

 
    /** 
 
    * Set description 
 
    * 
 
    * @param string $description 
 
    * @return CarousselImg 
 
    */ 
 
    public function setDescription($description) 
 
    { 
 
     $this->description = $description; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get description 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getDescription() 
 
    { 
 
     return $this->description; 
 
    } 
 

 
    /** 
 
    * Set caroussel 
 
    * 
 
    * @param \AppBundle\Entity\Caroussel $caroussel 
 
    * @return CarousselImg 
 
    */ 
 
    public function setCaroussel(\AppBundle\Entity\Caroussel $caroussel = null) 
 
    { 
 
     $this->caroussel = $caroussel; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get caroussel 
 
    * 
 
    * @return \AppBundle\Entity\Caroussel 
 
    */ 
 
    public function getCaroussel() 
 
    { 
 
     return $this->caroussel; 
 
    } 
 
}
ため

$builder->add('title')->add('carousselImgs', new CarousselImgType()); 

感謝です

<?php 
 

 
namespace AppBundle\Entity; 
 

 
use Doctrine\ORM\Mapping as ORM; 
 
use Doctrine\Common\Collections\ArrayCollection; 
 
/** 
 
* Caroussel 
 
* 
 
* @ORM\Table(name="caroussel") 
 
* @ORM\Entity(repositoryClass="AppBundle\Repository\CarousselRepository") 
 
*/ 
 
class Caroussel 
 
{ 
 
    /** 
 
    * @var int 
 
    * 
 
    * @ORM\Column(name="id", type="integer") 
 
    * @ORM\Id 
 
    * @ORM\GeneratedValue(strategy="AUTO") 
 
    */ 
 
    private $id; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="title", type="string", length=255, nullable=true) 
 
    */ 
 
    private $title; 
 

 
    /** 
 
    * @ORM\ManyToOne(targetEntity="Post", inversedBy="caroussels") 
 
    * @ORM\JoinColumn(name="post_id", referencedColumnName="id") 
 
    */ 
 

 
    private $post; 
 
    /** 
 
    * @ORM\OneToMany(targetEntity="CarousselImg", mappedBy="caroussel", cascade={"persist"}) 
 
    */ 
 
    private $carousselImgs; 
 

 
    public function __construct() 
 
    { 
 
     $this->carousselImgs = new ArrayCollection(); 
 
    } 
 

 
    public function __toString() 
 
    { 
 
     return $this->title; 
 
    } 
 
    /** 
 
    * Get id 
 
    * 
 
    * @return integer 
 
    */ 
 
    public function getId() 
 
    { 
 
     return $this->id; 
 
    } 
 

 
    /** 
 
    * Set title 
 
    * 
 
    * @param string $title 
 
    * @return Caroussel 
 
    */ 
 
    public function setTitle($title) 
 
    { 
 
     $this->title = $title; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get title 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getTitle() 
 
    { 
 
     return $this->title; 
 
    } 
 

 
    /** 
 
    * Set post 
 
    * 
 
    * @param \AppBundle\Entity\Post $post 
 
    * @return Caroussel 
 
    */ 
 
    public function setPost(\AppBundle\Entity\Post $post = null) 
 
    { 
 
     $this->post = $post; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get post 
 
    * 
 
    * @return \AppBundle\Entity\Post 
 
    */ 
 
    public function getPost() 
 
    { 
 
     return $this->post; 
 
    } 
 

 
    /** 
 
    * Add carousselImgs 
 
    * 
 
    * @param \AppBundle\Entity\CarousselImg $carousselImgs 
 
    * @return Caroussel 
 
    */ 
 
    public function addCarousselImg(\AppBundle\Entity\CarousselImg $carousselImgs) 
 
    { 
 
     $carousselImgs->setCaroussel($this); 
 
     $this->carousselImgs[] = $carousselImgs; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Remove carousselImgs 
 
    * 
 
    * @param \AppBundle\Entity\CarousselImg $carousselImgs 
 
    */ 
 
    public function removeCarousselImg(\AppBundle\Entity\CarousselImg $carousselImgs) 
 
    { 
 
     $this->carousselImgs->removeElement($carousselImgs); 
 
    } 
 

 
    /** 
 
    * Get carousselImgs 
 
    * 
 
    * @return \Doctrine\Common\Collections\Collection 
 
    */ 
 
    public function getCarousselImgs() 
 
    { 
 
     return $this->carousselImgs; 
 
    } 
 
}

<?php 
 

 
namespace AppBundle\Entity; 
 

 
use Doctrine\ORM\Mapping as ORM; 
 
use Doctrine\Common\Collections\ArrayCollection; 
 

 
/** 
 
* Post 
 
* 
 
* @ORM\Table(name="post") 
 
* @ORM\Entity(repositoryClass="AppBundle\Repository\PostRepository") 
 
*/ 
 
class Post 
 
{ 
 
    /** 
 
    * @var int 
 
    * 
 
    * @ORM\Column(name="id", type="integer") 
 
    * @ORM\Id 
 
    * @ORM\GeneratedValue(strategy="AUTO") 
 
    */ 
 
    private $id; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="title", type="string", length=255, nullable=true) 
 
    */ 
 
    private $title; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="subTitle", type="string", length=255, nullable=true) 
 
    */ 
 
    private $subTitle; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="description", type="text", nullable=true) 
 
    */ 
 
    private $description; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="thumble", type="string", length=255, nullable=true) 
 
    */ 
 
    private $thumble; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="postFirstImg", type="string", length=255, nullable=true) 
 
    */ 
 
    private $postFirstImg; 
 

 
    /** 
 
    * @var int 
 
    * 
 
    * @ORM\Column(name="activeOrNot", type="integer") 
 
    */ 
 
    private $activeOrNot; 
 

 
    /** 
 
    * @var string 
 
    * 
 
    * @ORM\Column(name="type", type="string", length=255) 
 
    */ 
 
    private $type; 
 
    /** 
 
    * @ORM\ManyToOne(targetEntity="Category", inversedBy="posts") 
 
    * @ORM\JoinColumn(name="category_id", referencedColumnName="id") 
 
    */ 
 
    protected $category; 
 

 
    /** 
 
    * @ORM\ManyToOne(targetEntity="Seo", inversedBy="posts", cascade={"persist", "remove"}) 
 
    * @ORM\JoinColumn(name="seo_id", referencedColumnName="id") 
 
    */ 
 

 
    protected $seo; 
 

 
    /** 
 
    * @ORM\OneToMany(targetEntity="Video", mappedBy="post", cascade={"persist"}) 
 
    */ 
 

 
    private $videos; 
 
    /** 
 
    * @ORM\OneToMany(targetEntity="Citation", mappedBy="post", cascade={"persist"}) 
 
    */ 
 
    private $citations; 
 
    /** 
 
    * @ORM\OneToMany(targetEntity="Caroussel", mappedBy="post", cascade={"persist"}) 
 
    */ 
 
    private $caroussels; 
 

 
    public function __construct() 
 
    { 
 
     $this->videos = new ArrayCollection(); 
 
     $this->citations = new ArrayCollection(); 
 
     $this->caroussels = new ArrayCollection(); 
 
    } 
 

 

 
    /** 
 
    * Get id 
 
    * 
 
    * @return integer 
 
    */ 
 
    public function getId() 
 
    { 
 
     return $this->id; 
 
    } 
 

 
    /** 
 
    * Set title 
 
    * 
 
    * @param string $title 
 
    * @return Post 
 
    */ 
 
    public function setTitle($title) 
 
    { 
 
     $this->title = $title; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get title 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getTitle() 
 
    { 
 
     return $this->title; 
 
    } 
 

 
    /** 
 
    * Set subTitle 
 
    * 
 
    * @param string $subTitle 
 
    * @return Post 
 
    */ 
 
    public function setSubTitle($subTitle) 
 
    { 
 
     $this->subTitle = $subTitle; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get subTitle 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getSubTitle() 
 
    { 
 
     return $this->subTitle; 
 
    } 
 

 
    /** 
 
    * Set description 
 
    * 
 
    * @param string $description 
 
    * @return Post 
 
    */ 
 
    public function setDescription($description) 
 
    { 
 
     $this->description = $description; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get description 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getDescription() 
 
    { 
 
     return $this->description; 
 
    } 
 

 
    /** 
 
    * Set thumble 
 
    * 
 
    * @param string $thumble 
 
    * @return Post 
 
    */ 
 
    public function setThumble($thumble) 
 
    { 
 
     $this->thumble = $thumble; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get thumble 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getThumble() 
 
    { 
 
     return $this->thumble; 
 
    } 
 

 
    /** 
 
    * Set postFirstImg 
 
    * 
 
    * @param string $postFirstImg 
 
    * @return Post 
 
    */ 
 
    public function setPostFirstImg($postFirstImg) 
 
    { 
 
     $this->postFirstImg = $postFirstImg; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get postFirstImg 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getPostFirstImg() 
 
    { 
 
     return $this->postFirstImg; 
 
    } 
 

 
    /** 
 
    * Set activeOrNot 
 
    * 
 
    * @param integer $activeOrNot 
 
    * @return Post 
 
    */ 
 
    public function setActiveOrNot($activeOrNot) 
 
    { 
 
     $this->activeOrNot = $activeOrNot; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get activeOrNot 
 
    * 
 
    * @return integer 
 
    */ 
 
    public function getActiveOrNot() 
 
    { 
 
     return $this->activeOrNot; 
 
    } 
 

 
    /** 
 
    * Set type 
 
    * 
 
    * @param string $type 
 
    * @return Post 
 
    */ 
 
    public function setType($type) 
 
    { 
 
     $this->type = $type; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get type 
 
    * 
 
    * @return string 
 
    */ 
 
    public function getType() 
 
    { 
 
     return $this->type; 
 
    } 
 

 
    /** 
 
    * Set category 
 
    * 
 
    * @param \AppBundle\Entity\Category $category 
 
    * @return Post 
 
    */ 
 
    public function setCategory(\AppBundle\Entity\Category $category = null) 
 
    { 
 
     $this->category = $category; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get category 
 
    * 
 
    * @return \AppBundle\Entity\Category 
 
    */ 
 
    public function getCategory() 
 
    { 
 
     return $this->category; 
 
    } 
 

 
    /** 
 
    * Set seo 
 
    * 
 
    * @param \AppBundle\Entity\Seo $seo 
 
    * @return Post 
 
    */ 
 
    public function setSeo(\AppBundle\Entity\Seo $seo = null) 
 
    { 
 
     $this->seo = $seo; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Get seo 
 
    * 
 
    * @return \AppBundle\Entity\Seo 
 
    */ 
 
    public function getSeo() 
 
    { 
 
     return $this->seo; 
 
    } 
 

 

 
    /** 
 
    * Add videos 
 
    * 
 
    * @param \AppBundle\Entity\Video $videos 
 
    * @return Post 
 
    */ 
 
    public function addVideo(\AppBundle\Entity\Video $videos) 
 
    { 
 
     $videos->setPost($this); 
 
     $this->videos[] = $videos; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Remove videos 
 
    * 
 
    * @param \AppBundle\Entity\Video $videos 
 
    */ 
 
    public function removeVideo(\AppBundle\Entity\Video $videos) 
 
    { 
 
     $this->videos->removeElement($videos); 
 
    } 
 

 
    /** 
 
    * Get videos 
 
    * 
 
    * @return \Doctrine\Common\Collections\Collection 
 
    */ 
 
    public function getVideos() 
 
    { 
 
     return $this->videos; 
 
    } 
 

 
    /** 
 
    * Add citations 
 
    * 
 
    * @param \AppBundle\Entity\Citation $citations 
 
    * @return Post 
 
    */ 
 
    public function addCitation(\AppBundle\Entity\Citation $citations) 
 
    { 
 
     $citations->setPost($this); 
 
     $this->citations[] = $citations; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Remove citations 
 
    * 
 
    * @param \AppBundle\Entity\Citation $citations 
 
    */ 
 
    public function removeCitation(\AppBundle\Entity\Citation $citations) 
 
    { 
 
     $this->citations->removeElement($citations); 
 
    } 
 

 
    /** 
 
    * Get citations 
 
    * 
 
    * @return \Doctrine\Common\Collections\Collection 
 
    */ 
 
    public function getCitations() 
 
    { 
 
     return $this->citations; 
 
    } 
 
    public function __toString(){ 
 
     return $this->type; 
 
    } 
 

 
    /** 
 
    * Add caroussels 
 
    * 
 
    * @param \AppBundle\Entity\Caroussel $caroussels 
 
    * @return Post 
 
    */ 
 
    public function addCaroussel(\AppBundle\Entity\Caroussel $caroussels, \AppBundle\Entity\CarousselImg $carousselImg) 
 
    { 
 
     $caroussels->setPost($this); 
 
     $carousselImg->setCaroussel($caroussels); 
 
     $this->caroussels[] = $caroussels; 
 

 
     return $this; 
 
    } 
 

 
    /** 
 
    * Remove caroussels 
 
    * 
 
    * @param \AppBundle\Entity\Caroussel $caroussels 
 
    */ 
 
    public function removeCaroussel(\AppBundle\Entity\Caroussel $caroussels) 
 
    { 
 
     $this->caroussels->removeElement($caroussels); 
 
    } 
 

 
    /** 
 
    * Get caroussels 
 
    * 
 
    * @return \Doctrine\Common\Collections\Collection 
 
    */ 
 
    public function getCaroussels() 
 
    { 
 
     return $this->caroussels; 
 
    } 
 
    
 
}

答えて

0

CarousselImgType::classnew CarousselImgType()を交換してください。 addメソッドの2番目のパラメータは、オブジェクトではなくフィールドの型を持つことが必要です。

編集:CarousselImgの代わりにCarousselImgCarousselに渡しています。してください答えを

->add('title') 
->add('carousselImgs', CollectionType::class, array(
    'entry_type' => CarousselImgType::class, 
    //... 
) 
+0

こんにちは感謝しかし、私は –

+0

たちは、クラスの完全なコードを持つことができ、同じエラーが動作しdidnot _CarousselType_と_AppBundle \エンティティ\ Caroussel_:あなたはあなたのCarousselをタイプでそのようなことをすればよいですか? –

+0

ueah投稿を更新します –

関連する問題