Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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 Symfony 3预期”字样;条令\Common\Collections\ArrayCollection“;鉴于使用OneToMany时_Php_Symfony_Doctrine Orm_Symfony Forms_Symfony 3.1 - Fatal编程技术网

Php Symfony 3预期”字样;条令\Common\Collections\ArrayCollection“;鉴于使用OneToMany时

Php Symfony 3预期”字样;条令\Common\Collections\ArrayCollection“;鉴于使用OneToMany时,php,symfony,doctrine-orm,symfony-forms,symfony-3.1,Php,Symfony,Doctrine Orm,Symfony Forms,Symfony 3.1,我对此错误有问题: Expected argument of type "AppBundle\Entity\BusVehiclesAmenities", "Doctrine\Common\Collections\ArrayCollection" given The association AppBundle\Entity\BusVehiclesAmenities#bus refers to the inverse side field AppBundle\Entity\BusVehicles#

我对此错误有问题:

Expected argument of type "AppBundle\Entity\BusVehiclesAmenities", "Doctrine\Common\Collections\ArrayCollection" given
The association AppBundle\Entity\BusVehiclesAmenities#bus refers to the inverse side field AppBundle\Entity\BusVehicles#busVehiclesAmenities which does not exist.
编辑3

经过几次评论后,我应用了建议,现在错误消失了(从公共汽车车辆设施实体中删除ArrayCollection,从控制器中删除设置公共汽车车辆设施实体,并删除所有映射实体上的ORM连接列)

现在我有一个错误:

Expected argument of type "AppBundle\Entity\BusVehiclesAmenities", "Doctrine\Common\Collections\ArrayCollection" given
The association AppBundle\Entity\BusVehiclesAmenities#bus refers to the inverse side field AppBundle\Entity\BusVehicles#busVehiclesAmenities which does not exist.
映射实体

巴士车辆:

/* @ORM\OneToMany(
     *     targetEntity="BusVehiclesAmenities",
     *     mappedBy="bus",
     *     fetch="EXTRA_LAZY",
     *     orphanRemoval=true,
     *     cascade={"persist"}

     * )
     *
     */

    private $busVehiclesAmenities;
公交车辆设施实体:

private $bus;

    /**
     *
     * @ORM\ManyToOne(targetEntity="Amenities", inversedBy="amenities")
     * @ORM\JoinColumn(name="amenities_id", referencedColumnName="id")
     *
     */
我正在使用表单集合来创建一对一的关系。问题是当我添加新数据时,我遇到了这个错误

有人知道问题出在哪里吗

代码: 总线实体(父级)

舒适实体(儿童)

编辑1:

我从BusVehicleSamentites实体中删除了ArrayCollection,但在提交表单时仍然出现相同的错误

编辑2:

附加表格

公共汽车车辆形式类型

<?php

namespace AdminBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;




class BusVehiclesType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('licencePlate')
            ->add('chassisNumber')
            ->add('manufacturer')
            ->add('busVehiclesAmenities', CollectionType::class, array(
                'entry_type'   => BusVehiclesAmenitiesType::class,
                'prototype' => true,
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
            ));
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\BusVehicles',
            'cascade_validation' => true,

        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'adminbundle_busvehicles';
    }


}
    <?php

namespace AdminBundle\Form\Type;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use AppBundle\Entity\BusVehiclesAmenities;
use Symfony\Component\OptionsResolver\OptionsResolver;


class BusVehiclesAmenitiesType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('price', NumberType::class, array(

            ))
            ->add('amenities', EntityType::class, array(
                'class' =>'AppBundle:Amenities',
                'choice_label' => 'name',
            ))

        ;

    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => BusVehiclesAmenities::class
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'appbundle_busvehiclesamenities';
    }


}

公交车辆便利设施->公交
是一个对象,而不是集合。行
$this->bus=newarraycollection()没有理由存在于子实体中

您希望在作为单个对象的对象(总线)中实现多个一个、多个(基本属性)又称为
ArrayCollection

编辑

在控制器中,您可以执行以下操作

$bus->setBusVehiclesAmenities($busAmenities);
这是不必要的。该表格将自行处理收集事宜。魔力

您的错误可能来自此调用,但这是因为您试图说
arrayCollection=object
,这是不可能的

  public function setBusVehiclesAmenities(BusVehiclesAmenities $busVehiclesAmenities)
    {
        // ArrayCollection = Object
        $this->busVehiclesAmenities = $busVehiclesAmenities;
        return $this;
    }
您可以尝试执行
setBusVehicleComplements(ArrayCollection$BusVehicleComplements)
Collection
,我不知道,或者删除
setBusVehicleComplements
方法。(我个人会删除该方法)

此外,您还应该在子对象中检查getter/setter的
bus
,这次您的变量是单个对象,只需执行
getBus()
setBus($bus)
,而不是添加和删除


希望这对您有所帮助

公交车车辆设施->公交车
是一个对象,而不是一个集合。行
$this->bus=newarraycollection()没有理由存在于子实体中

您希望在作为单个对象的对象(总线)中实现多个一个、多个(基本属性)又称为
ArrayCollection

编辑

在控制器中,您可以执行以下操作

$bus->setBusVehiclesAmenities($busAmenities);
这是不必要的。该表格将自行处理收集事宜。魔力

您的错误可能来自此调用,但这是因为您试图说
arrayCollection=object
,这是不可能的

  public function setBusVehiclesAmenities(BusVehiclesAmenities $busVehiclesAmenities)
    {
        // ArrayCollection = Object
        $this->busVehiclesAmenities = $busVehiclesAmenities;
        return $this;
    }
您可以尝试执行
setBusVehicleComplements(ArrayCollection$BusVehicleComplements)
Collection
,我不知道,或者删除
setBusVehicleComplements
方法。(我个人会删除该方法)

此外,您还应该在子对象中检查getter/setter的
bus
,这次您的变量是单个对象,只需执行
getBus()
setBus($bus)
,而不是添加和删除

希望这可以帮助您

从礼仪实体(儿童)中删除这部分代码:

public function __construct()
{
    $this->bus = new ArrayCollection();
}
如果表单的定义正确,它应该可以解决您的问题

解释-此实体中的总线是OneToMany关系的拥有方。它始终是一个,不能是一个集合。

从便利设施实体(子项)中删除这部分代码:

public function __construct()
{
    $this->bus = new ArrayCollection();
}
如果表单的定义正确,它应该可以解决您的问题


解释-此实体中的总线是OneToMany关系的拥有方。它总是一个,不可能是收藏。

我遇到了与你类似的问题。我所做的就是移除JoinColumn。它实际上是多余的。这是Symfony的“魔力”之一,会让IMHO恼火。只要确保你的OneToMany注释正确地指向你的ManyToMany。下面是一个示例--在my User.php实体中:

/**
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\UserStats", mappedBy="user")
 */
private $userStats;
这是在被加入的实体中(UserStats.php):

正如您所看到的,没有JoinColumn,因此一切都运行得很好。我希望这对你有帮助。:)

确保你使用了我上面提到的正确路径,即

* (targetEntity="AppBundle\Entity\User", inversedBy="userStats")

我遇到了与你类似的问题。我所做的就是移除JoinColumn。它实际上是多余的。这是Symfony的“魔力”之一,会让IMHO恼火。只要确保你的OneToMany注释正确地指向你的ManyToMany。下面是一个示例--在my User.php实体中:

/**
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\UserStats", mappedBy="user")
 */
private $userStats;
这是在被加入的实体中(UserStats.php):

正如您所看到的,没有JoinColumn,因此一切都运行得很好。我希望这对你有帮助。:)

确保你使用了我上面提到的正确路径,即

* (targetEntity="AppBundle\Entity\User", inversedBy="userStats")

谢谢你的回答。我删除了代码,但我仍然有相同的错误,当我张贴表单感谢你们的时间和努力。如果控制器i中没有“SetBusVehicleSciployments”,则公共汽车设施集合是空的。谢谢您的回答。我删除了代码,但我仍然有相同的错误,当我张贴表单感谢你们的时间和努力。如果控制器i中没有“SetBusVehicleComplements”,则公交车设施的表格集合为空。因此您必须与我们共享您的表格:-)因此您必须与我们共享您的表格:-)感谢您的评论。我使用了你的建议,但我有一个错误。我想同样的事情也发生在我身上,最后,JoinColumn没有被使用。期待看到您的更新。好的-删除此:@ORM\JoinColumn(name=“便利设施”\u id“,referencedColumnName=“id”)。两个实体中都不需要JoinColumn。如果你看一下我的例子,我一个都没有,这是我最初指出的。我敢打赌这能解决问题。我把它们都从巴士设施中移除了,错误仍然存在。我在公共汽车上还剩下一些