Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2:具有自定义链接表的多对多_Php_Forms_Symfony_Doctrine Orm - Fatal编程技术网

Php Symfony2:具有自定义链接表的多对多

Php Symfony2:具有自定义链接表的多对多,php,forms,symfony,doctrine-orm,Php,Forms,Symfony,Doctrine Orm,我正在制作一个包含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\PcastSuppo

我正在制作一个包含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;
我的二传手和传接手:

/**
 * 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);
非常感谢你的帮助


我尝试在一个简单的情况下使用多对多关系(用户、公司和用户\公司实体),但在尝试将公司添加到用户时遇到了一个问题:

警告:oci\u bind\u by_name()[]:在C:\wamp\www\php\Promocast\Symfony\vendor\doctrine dbal\lib\doctrine\dbal\Driver\OCI8\OCI8Statement.php第113行中用于绑定的变量无效

我在谷歌上搜索了很多,但是我没有找到关于这个错误的任何信息。。。根据stack trace,错误出现在尝试添加公司对象时:

array('column'=>':param10','variable'=>object(PcastCompany),'type'=>'1')

我的用户实体(兴业银行=公司):

我的公司实体:

/**
 * @ORM\ManyToMany(targetEntity="ImUser", mappedBy="societes")
 */
private $users;

public function __construct() {
    $this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
如果有人知道


谢谢

您不应该有表示链接表的实体。如果两个实体都正确注释,则条令将自行处理链接表的创建

此外,首先不需要任何链接表来处理多对一关系,您要做的是在两个实体中使用多对多注释


您不应该拥有表示链接表的实体。如果两个实体都正确注释,则条令将自行处理链接表的创建

此外,首先不需要任何链接表来处理多对一关系,您要做的是在两个实体中使用多对多注释


从基础开始。我对很多其他的东西很好奇,所以我抓住了你们的实体作为测试用例。在深入研究表单等之前,请确保您可以从命令行执行一个简单的测试用例,例如:

use Zayso\ArbiterBundle\Entity\PcastSociete as Company;
use Zayso\ArbiterBundle\Entity\ImUser       as User;

protected function test1()
{
    $em = $this->getContainer()->get('doctrine.orm.entity_manager');
    $company = new Company();
    $em->persist($company);

    $user = new User();
    $user->addSociete($company);
    $em->persist($user);

    $em->flush();

}
对于我使用的实体:

namespace Zayso\ArbiterBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 */
class ImUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer",name="iduser") 
 * @ORM\GeneratedValue
 */
protected $id;

public function getId()    { return $this->id; }

/**
 * @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(PcastSociete $societe)
{
    $this->societes[] = $societe;
}
public function __construct() 
{
    $this->societes = new ArrayCollection();
}

}

namespace Zayso\ArbiterBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 */
class PcastSociete
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer", name="idsociete") 
 * @ORM\GeneratedValue
 */
protected $id;

public function getId()    { return $this->id; }

/**
 * @ORM\ManyToMany(targetEntity="ImUser", mappedBy="societes")
 */
private $users;

public function __construct() 
{
    $this->users = new ArrayCollection();
}
}

完成上述工作后,我们可以继续处理表单问题。

从基础开始。我对很多其他的东西很好奇,所以我抓住了你们的实体作为测试用例。在深入研究表单等之前,请确保您可以从命令行执行一个简单的测试用例,例如:

use Zayso\ArbiterBundle\Entity\PcastSociete as Company;
use Zayso\ArbiterBundle\Entity\ImUser       as User;

protected function test1()
{
    $em = $this->getContainer()->get('doctrine.orm.entity_manager');
    $company = new Company();
    $em->persist($company);

    $user = new User();
    $user->addSociete($company);
    $em->persist($user);

    $em->flush();

}
对于我使用的实体:

namespace Zayso\ArbiterBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 */
class ImUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer",name="iduser") 
 * @ORM\GeneratedValue
 */
protected $id;

public function getId()    { return $this->id; }

/**
 * @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(PcastSociete $societe)
{
    $this->societes[] = $societe;
}
public function __construct() 
{
    $this->societes = new ArrayCollection();
}

}

namespace Zayso\ArbiterBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 */
class PcastSociete
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer", name="idsociete") 
 * @ORM\GeneratedValue
 */
protected $id;

public function getId()    { return $this->id; }

/**
 * @ORM\ManyToMany(targetEntity="ImUser", mappedBy="societes")
 */
private $users;

public function __construct() 
{
    $this->users = new ArrayCollection();
}
}

完成上面的工作,然后我们可以继续讨论表单问题。

好的,我会尝试,只问一个问题,条令如何创建此链接表?(在数据库中或类似实体?)谢谢您的回答!在多对多注释中,必须提供用作链接表的表的名称。如果它已经存在,它只会使用它,如果它不存在,它只会在数据库中创建表并从现在开始使用它。好的,我会尝试,只是一个问题,条令如何创建这个链接表?(在数据库中或类似实体?)谢谢您的回答!在多对多注释中,必须提供用作链接表的表的名称。如果它已经存在,它只会使用它,如果它不存在,它只会在数据库中创建表并从现在开始使用它。谢谢你的回答,我没有说,但我的测试实际上和你的一样。我只需使用一个表单填写我的用户实体,然后手动添加一个公司:
$test\u societe=$em->getRepository('MyappMyBundle:PcastSociete')->find(49)$newUser->addSociete($test_societe)
然后只保留用户,这就是为什么我不理解symfony错误,不确定该建议什么,除了可能使用mysql数据库进行测试。PcastCompany(由于您的错误)有点可疑。会期待像PcastSociete这样的东西。设置一个小的测试环境,这样您就可以从命令行运行东西,这将在将来为您节省大量的工作。好的,我尝试使用另一个示例,问题是每次我尝试在setter中持久化一个带有对象的实体时,都会出现此错误(
警告:oci\u bind\u by\u name()
)。像条令不明白,他坚持的时候只需要取这个物体的id。谢谢你的回答,我没有说,但我的测试实际上和你的一样。我只需使用一个表单填写我的用户实体,然后手动添加一个公司:
$test\u societe=$em->getRepository('MyappMyBundle:PcastSociete')->find(49)$newUser->addSociete($test_societe)
然后只保留用户,这就是为什么我不理解symfony错误,不确定该建议什么,除了可能使用mysql数据库进行测试。PcastCompany(由于您的错误)有点可疑。会期待像PcastSociete这样的东西。设置一个小的测试环境,这样您就可以从命令行运行东西,这将在将来为您节省大量的工作。好的,我尝试使用另一个示例,问题是每次我尝试在setter中持久化一个带有对象的实体时,都会出现此错误(
警告:oci\u bind\u by\u name()
)。Like doctrine不明白,他在坚持时只需获取该对象的id。这可能会有帮助:这可能会有帮助: