我工作在窗體上有3個實體:Symfony2的:許多一對多帶有自定義鏈接表
- 順序(idorder)
- 支持參考表(idsupport)
- 鏈接表(idorder,idsupport)
,當我嘗試選擇一個或多個支持我得到這個錯誤:
Catchable Fatal Error: Argument 1 passed to Myapp\MyBundle\Entity\PcastCmdsupports::setIdsupports() must be an instance of Myapp\MyBundle\Entity\PcastSupports, instance of Doctrine\Common\Collections\ArrayCollection given,
called in C:\wamp\www\php\Symfony\vendor\symfony\src\Symfony\Component\Form\Util\PropertyPath.php on line 347 and defined in C:\wamp\www\php\Symfony\src\Myapp\MyBundle\Entity\PcastCmdsupports.php line 62
,因爲我已經創造了我看到了,我可以簡單地在我的鏈接表中創建了2個多到一的關係在網絡上我的鏈接表:
/**
* @var PcastSupports
*
* @ORM\ManyToOne(targetEntity="PcastSupports")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="IDSUPPORTS", referencedColumnName="IDSUPPORTS")
* })
*/
private $idsupports;
/**
* @var PcastOrder
*
* @ORM\ManyToOne(targetEntity="PcastOrder")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="IDORDER", referencedColumnName="IDORDER")
* })
*/
private $idorder;
和我的getter和setter方法:
/**
* Set idsupports
*
*/
public function setIdsupports(\Myapp\MyBundle\Entity\PcastSupports $idsupports)
{
$this->idsupports = $idsupports;
}
/**
* Get idsupports
*
*/
public function getIdsupports()
{
return $this->idsupports;
}
/**
* Set idorder
*
*/
public function setIdcommande(\Myapp\MyBundle\Entity\PcastOrder $idorder)
{
$this->idorder = $idorder;
}
/**
* Get idorder
*
*/
public function getIdorder()
{
return $this->idorder;
}
在我的訂單我可以選擇一個或多個的支持,所以我創造了我的形式是這樣的:
$form_clips = $this->createFormBuilder($cmdclips)
->add('idorder', new CmdsupportsType)
->getForm();
最後我supportsType形式:
$builder
->add('idsupports', 'entity', array(
'class' => 'MyappMyBundle:PcastSupports',
'property' => 'name',
'expanded' => true,
'multiple' => true,
'query_builder' => function(EntityRepository $er)
{
return $er->createQueryBuilder('pts')
->orderBy('pts.idsupports','ASC');
},
));
我沒有使用任何arraycollection,所以我不明白這個問題。此問題發生在此行動中:
$form_clips->bindRequest($request);
非常感謝您的幫助!
我試圖使它在一個簡單的情況下,許多一對多的關係(用戶,公司和user_company實體)的工作,但我有一個問題,當我嘗試將公司添加到用戶:
Warning: oci_bind_by_name() [<a href='function.oci-bind-by-name'>function.oci-bind-by-name</a>]: Invalid variable used for bind in C:\wamp\www\php\Promocast\Symfony\vendor\doctrine-dbal\lib\Doctrine\DBAL\Driver\OCI8\OCI8Statement.php line 113
我google搜索了很多,但我沒有找到關於此錯誤的東西......據堆棧跟蹤誤差時學說嘗試添加該公司目標:
array('column' => ':param10', 'variable' => object(PcastCompany), 'type' => '1')
我的用戶實體(興業=公司):
/**
* @ORM\ManyToMany(targetEntity="PcastSociete", inversedBy="users")
* @ORM\JoinTable(name="PcastLienusersociete",
* joinColumns={@ORM\JoinColumn(name="ImUser_iduser", referencedColumnName="iduser")},
* inverseJoinColumns={@ORM\JoinColumn(name="PcastLienusersociete_idsociete", referencedColumnName="idsociete")}
*)
*/
private $societes;
public function getSocietes()
{
return $this->societes;
}
public function addSociete(\Myapp\MyBundle\Entity\PcastSociete $societe)
{
$this->societes[] = $societe;
}
我公司實體:
/**
* @ORM\ManyToMany(targetEntity="ImUser", mappedBy="societes")
*/
private $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
如果任何人有任何想法...
感謝
這可能有助於:http://www.prowebdev.us/2012/07/symfnoy2-many-to-many-relation-with.html – PMoubed 2013-03-11 00:33:54