【发布时间】:2012-03-20 15:42:11
【问题描述】:
我正在处理一个包含 3 个实体的表单:
- 订单(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;
还有我的 setter 和 getter:
/**
* 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
我在谷歌上搜索了很多,但我没有找到任何关于此错误的信息...根据堆栈跟踪,错误是当学说尝试添加公司对象时:
array('column' => ':param10', 'variable' => object(PcastCompany), 'type' => '1')
我的用户实体(societe = 公司):
/**
* @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();
}
如果有人有任何想法......
谢谢
【问题讨论】:
标签: php forms symfony doctrine-orm