1
我有實體:爲什麼在多重設置爲false時,Doctrine不會保存實體?
<?php
namespace BW\BlogBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* PostCustomField
*
* @ORM\Table(name="post_custom_field")
* @ORM\Entity(repositoryClass="BW\BlogBundle\Entity\PostCustomFieldRepository")
*/
class PostCustomField
{
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="BW\BlogBundle\Entity\CustomFieldProperty", inversedBy="postCustomFields")
*/
private $customFieldProperties;
public function __construct()
{
$this->customFieldProperties = new ArrayCollection();
}
/**
* Add customFieldProperties
*
* @param \BW\BlogBundle\Entity\CustomFieldProperty $customFieldProperties
* @return PostCustomField
*/
public function addCustomFieldProperty(\BW\BlogBundle\Entity\CustomFieldProperty $customFieldProperties)
{
$this->customFieldProperties[] = $customFieldProperties;
return $this;
}
/**
* Remove customFieldProperties
*
* @param \BW\BlogBundle\Entity\CustomFieldProperty $customFieldProperties
*/
public function removeCustomFieldProperty(\BW\BlogBundle\Entity\CustomFieldProperty $customFieldProperties)
{
$this->customFieldProperties->removeElement($customFieldProperties);
}
/**
* Get customFieldProperties
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCustomFieldProperties()
{
return $this->customFieldProperties;
}
,並有表單類型:
<?php
namespace BW\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PostCustomFieldType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('customFieldProperties', 'entity', array(
'class' => 'BW\BlogBundle\Entity\CustomFieldProperty',
'property' => 'name',
'multiple' => true,
'expanded' => true,
))
而且它很好地工作複選框,但是當我嘗試使用單選按鈕(設置'multiple' => false,
) - 這是使他們罰款,但是當我檢查,並設法實體保存到數據庫 - 我有一個錯誤:
Neither the property "customFieldProperties" nor one of the methods
"addCustomFieldProperty()"/"removeCustomFieldProperty()", "setCustomFieldProperties()",
"customFieldProperties()", "__set()" or "__call()" exist and have public access in class
"BW\BlogBundle\Entity\PostCustomField".
學說爲什麼不保存實體'multiple' => false
?
P.S. Symfony Standart Edition v2.5.0
我覺得'ManyToMany'關係有問題,不是嗎?但是我需要這個屬性的'ManyToMany'關係。 –
你有實體中的'customFieldProperties'屬性的getter/setter嗎? –
@DebreczeniAndrás我有getter,而不是setter我有添加方法就像我上面的例子 –