0
我做了Symfony2的Web應用程序,其中派斯具有西服的Arraycolletion:對象無法轉換爲字符串
派斯:
/**
* @ORM\OneToMany(targetEntity="Acc\ApssBundle\Entity\Suit", mappedBy="pais", cascade={"persist", "remove"})
* @Assert\Valid()
*/
protected $suits;
/**
* Constructor
*/
public function __construct()
{
$elements = array(new Suit('Suit1'), new Suit('Suit2'), new Suit('Suit3'), new Suit('Suit4'), new Suit('Suit5'));
$this->suits = new \Doctrine\Common\Collections\ArrayCollection($elements);
}
西裝
/**
* @ORM\ManyToOne(targetEntity=Acc\ApssBundle\Entity\Pais", inversedBy="suits")
*/
public $pais;
PaisSuitType
$builder->add('suits', 'collection', array(
'options' => array('data_class' => 'Acc\ApssBundle\Entity\Suit'),
'prototype' => true,
));
控制器:
$paises = array($es = new Pais(),
$it = new Pais(),
$mx = new Pais(),
$br = new Pais()
);
foreach ($paises as $pais){
$form[$i] = $this->createForm(new PaisType(),$pais);
$forms[ 'form'.(string)$i ] = $form[$i]->createView() ;
$i++;
}
嫩枝模板:
{% for suit in form0.suits %}
<td align = "center">{{ form(suit) }}</td>
{% endfor %}
在樹枝模板會出現錯誤。
而不是你當前問題,您在'$ pais'的orm中沒有'JoinColumn' – Javad