我的實體「produit」與此關係:Symfony的persit收集
/**
* @var \stdClass
*
* @ORM\ManyToMany(targetEntity="ListeBundle\Entity\GarDegatEaux", cascade={"persist"})
* @ORM\JoinTable(name="produit_garDegatEaux",
* joinColumns={@ORM\JoinColumn(name="produit_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="garDegatEaux_id", referencedColumnName="id", unique=false)})
*/
private $garDegatEaux;
一種形式類型象下面這樣:
->add('garDegatEaux', CollectionType::class, array('entry_type' => GarDegatEauxType::class,
'allow_add' => true,
'allow_delete' => true,
//'by_reference' => false,
'prototype' => true,
'label' => 'Coefficients dégât des eaux',
'entry_options' => array('label' => 'Coefficients'),
'attr' => array('class' => 'collection')
))
當通過參考被設置爲false我有這樣的錯誤:
在我的實體addGarDegatEau() 」/「 removeGarDegatEau()」。無論是屬性 「garDegatEaux」,也不的方法的一個 「addGarDegatEau()」/ 「removeGarDegatEau()」, 「setGarDegatEaux()」, 「garDegatEaux()」,「__set( )「或」__call()「存在並且在」DevisBundle \ Entity \ Produit「類中具有公共訪問權限。 by_reference 「:
$this->garDegatEaux = new \Doctrine\Common\Collections\ArrayCollection();
當並獲得..存在,有公共存取權限我也有我的構造函數與」
當然設置爲true沒有錯誤,但沒有任何提交的收集。當我轉儲表單之前的持久存在沒有任何ArrayCollection。
而當「by_reference」被評論沒有錯誤,但沒有任何也堅持ArrayCollection。
我的控制器:
public function creerProduitAction(Request $request) {
$produit = new Produit;
$formProduit = $this->createForm(ProduitType::class, $produit);
$formProduit->handleRequest($request);
if ($formProduit->isValid() && $formProduit->isSubmitted()) {
$em = $this->getDoctrine()->getManager();
$em->persist($produit);
$em->flush();
}
return $this->render('AdminBundle:Produit:creerProduit.html.twig', array(
'formProduit' => $formProduit->createView()
));
}
我以前收集在symfony 2.7而這個過程的工作。我使用symfony 2.8 atm。我不明白爲什麼收藏不會持久。
我修改了像這個garDegatEau這樣的變量名稱garDegatEaux。我有symfony要求的getters/setter:addGarDegatEau(\ ListeBundle \ Entity \ GarDegatEaux $ garDegatEau),以及remove和get。這是沒有更多的錯誤,但沒有任何承諾。我有antoher arraycollection沒有錯別字問題和相同的問題相同的配置 – stax