我工作在窗体上有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