Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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_Symfony_Doctrine Orm - Fatal编程技术网

Php Symfony2/条令,通过关系找到了一个新实体

Php Symfony2/条令,通过关系找到了一个新实体,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,试图在48小时内解决这个问题。我有一个实体BookingRequest.php,它的内容是: <?php namespace Kutiwa\PlatformBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * BookingRequest * * @ORM\Table(name="booking_request") * @ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\R

试图在48小时内解决这个问题。我有一个实体BookingRequest.php,它的内容是:

<?php

namespace Kutiwa\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * BookingRequest
 *
 * @ORM\Table(name="booking_request")
 * @ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\BookingRequestRepository")
 */
class BookingRequest
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="code", type="string", length=255, unique=true)
     */
    private $code;

    /**
     * @var string
     *
     * @ORM\Column(name="arrival", type="string", length=255)
     */
    private $arrival;

    /**
     * @var string
     *
     * @ORM\Column(name="departure", type="string", length=255)
     */
    private $departure;

    /**
     * @var string
     *
     * @ORM\Column(name="requestDate", type="string", length=255)
     */
    private $requestDate;

    /**
     * @var int
     *
     * @ORM\Column(name="rooms", type="integer")
     */
    private $rooms;

    /**
     * @var string
     *
     * @ORM\Column(name="minPricing", type="string", length=255)
     */
    private $minPricing;

    /**
     * @var string
     *
     * @ORM\Column(name="maxPricing", type="string", length=255)
     */
    private $maxPricing;

    /**
     * @var string
     *
     * @ORM\Column(name="customerName", type="string", length=255)
     */
    private $customerName;

    /**
     * @var string
     *
     * @ORM\Column(name="customerEmail", type="string", length=255, nullable=true)
     */
    private $customerEmail;

    /**
     * @var string
     *
     * @ORM\Column(name="customerPhone", type="string", length=255)
     */
    private $customerPhone;

    /**
     * @ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
     * @ORM\JoinColumn(nullable=false)
     */
    private $destinationCity;

    /**
     * @ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\City")
     * @ORM\JoinColumn(nullable=false)
     */
    private $customerCity;

    /**
     * @ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\MissionConfig", cascade={"persist"})
     */
    private $missionConfig;

    /**
     * @ORM\OneToOne(targetEntity="Kutiwa\PlatformBundle\Entity\TourismConfig", cascade={"persist"})
     */
    private $tourismConfig;

    /**
     * @ORM\OneToMany(targetEntity="Kutiwa\PlatformBundle\Entity\RoomsConfig", mappedBy="bookingRequest")
     */
    private $roomsConfigs;


    public function __construct() {
        $this->setRequestDate(date("d/m/Y"));
    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set code
     *
     * @param string $code
     *
     * @return BookingRequest
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

    /**
     * Get code
     *
     * @return string
     */
    public function getCode()
    {
        return $this->code;
    }

    /**
     * Set arrival
     *
     * @param string $arrival
     *
     * @return BookingRequest
     */
    public function setArrival($arrival)
    {
        $this->arrival = $arrival;

        return $this;
    }

    /**
     * Get arrival
     *
     * @return string
     */
    public function getArrival()
    {
        return $this->arrival;
    }

    /**
     * Set departure
     *
     * @param string $departure
     *
     * @return BookingRequest
     */
    public function setDeparture($departure)
    {
        $this->departure = $departure;

        return $this;
    }

    /**
     * Get departure
     *
     * @return string
     */
    public function getDeparture()
    {
        return $this->departure;
    }

    /**
     * Set requestDate
     *
     * @param string $requestDate
     *
     * @return BookingRequest
     */
    public function setRequestDate($requestDate)
    {
        $this->requestDate = $requestDate;

        return $this;
    }

    /**
     * Get requestDate
     *
     * @return string
     */
    public function getRequestDate()
    {
        return $this->requestDate;
    }

    /**
     * Set rooms
     *
     * @param integer $rooms
     *
     * @return BookingRequest
     */
    public function setRooms($rooms)
    {
        $this->rooms = $rooms;

        return $this;
    }

    /**
     * Get rooms
     *
     * @return integer
     */
    public function getRooms()
    {
        return $this->rooms;
    }

    /**
     * Set minPricing
     *
     * @param string $minPricing
     *
     * @return BookingRequest
     */
    public function setMinPricing($minPricing)
    {
        $this->minPricing = $minPricing;

        return $this;
    }

    /**
     * Get minPricing
     *
     * @return string
     */
    public function getMinPricing()
    {
        return $this->minPricing;
    }

    /**
     * Set maxPricing
     *
     * @param string $maxPricing
     *
     * @return BookingRequest
     */
    public function setMaxPricing($maxPricing)
    {
        $this->maxPricing = $maxPricing;

        return $this;
    }

    /**
     * Get maxPricing
     *
     * @return string
     */
    public function getMaxPricing()
    {
        return $this->maxPricing;
    }

    /**
     * Set customerName
     *
     * @param string $customerName
     *
     * @return BookingRequest
     */
    public function setCustomerName($customerName)
    {
        $this->customerName = $customerName;

        return $this;
    }

    /**
     * Get customerName
     *
     * @return string
     */
    public function getCustomerName()
    {
        return $this->customerName;
    }

    /**
     * Set customerEmail
     *
     * @param string $customerEmail
     *
     * @return BookingRequest
     */
    public function setCustomerEmail($customerEmail)
    {
        $this->customerEmail = $customerEmail;

        return $this;
    }

    /**
     * Get customerEmail
     *
     * @return string
     */
    public function getCustomerEmail()
    {
        return $this->customerEmail;
    }

    /**
     * Set customerPhone
     *
     * @param string $customerPhone
     *
     * @return BookingRequest
     */
    public function setCustomerPhone($customerPhone)
    {
        $this->customerPhone = $customerPhone;

        return $this;
    }

    /**
     * Get customerPhone
     *
     * @return string
     */
    public function getCustomerPhone()
    {
        return $this->customerPhone;
    }

    /**
     * Set destinationCity
     *
     * @param \Kutiwa\PlatformBundle\Entity\City $destinationCity
     *
     * @return BookingRequest
     */
    public function setDestinationCity(\Kutiwa\PlatformBundle\Entity\City $destinationCity)
    {
        $this->destinationCity = $destinationCity;

        return $this;
    }

    /**
     * Get destinationCity
     *
     * @return \Kutiwa\PlatformBundle\Entity\City
     */
    public function getDestinationCity()
    {
        return $this->destinationCity;
    }

    /**
     * Set customerCity
     *
     * @param \Kutiwa\PlatformBundle\Entity\City $customerCity
     *
     * @return BookingRequest
     */
    public function setCustomerCity(\Kutiwa\PlatformBundle\Entity\City $customerCity)
    {
        $this->customerCity = $customerCity;

        return $this;
    }

    /**
     * Get customerCity
     *
     * @return \Kutiwa\PlatformBundle\Entity\City
     */
    public function getCustomerCity()
    {
        return $this->customerCity;
    }

    /**
     * Set missionConfig
     *
     * @param \Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig
     *
     * @return BookingRequest
     */
    public function setMissionConfig(\Kutiwa\PlatformBundle\Entity\MissionConfig $missionConfig = null)
    {
        $this->missionConfig = $missionConfig;

        return $this;
    }

    /**
     * Get missionConfig
     *
     * @return \Kutiwa\PlatformBundle\Entity\MissionConfig
     */
    public function getMissionConfig()
    {
        return $this->missionConfig;
    }

    /**
     * Set tourismConfig
     *
     * @param \Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig
     *
     * @return BookingRequest
     */
    public function setTourismConfig(\Kutiwa\PlatformBundle\Entity\TourismConfig $tourismConfig = null)
    {
        $this->tourismConfig = $tourismConfig;

        return $this;
    }

    /**
     * Get tourismConfig
     *
     * @return \Kutiwa\PlatformBundle\Entity\TourismConfig
     */
    public function getTourismConfig()
    {
        return $this->tourismConfig;
    }

    /**
     * Add roomsConfig
     *
     * @param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
     *
     * @return BookingRequest
     */
    public function addRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
    {
        $this->roomsConfigs[] = $roomsConfig;

        return $this;
    }

    /**
     * Remove roomsConfig
     *
     * @param \Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig
     */
    public function removeRoomsConfig(\Kutiwa\PlatformBundle\Entity\RoomsConfig $roomsConfig)
    {
        $this->roomsConfigs->removeElement($roomsConfig);
    }

    /**
     * Get roomsConfigs
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getRoomsConfigs()
    {
        return $this->roomsConfigs;
    }
}

在持久化RoomsConfig之前,请尝试使用
findOneBy
查找BookingRequest,或使用任何方法查找实体,然后在持久化RoomsConfig之前,使用
setBookingRequest
设置找到的实体,尝试使用
findOneBy
查找BookingRequest,或者您用于查找实体的任何内容,然后使用
setBookingRequest

将找到的实体设置为“我不需要对城市和BookingRequest关系产生级联效应”,但您的映射明确说明了这一点。您能告诉我们更多关于您的型号吗?BookingRequest包含一个预订请求:用户信息(姓名、电话、城市)、预订的房间数,我已经在数据库中找到了我需要的所有城市,这就是为什么我不能在城市和BookingRequest之间产生级联效应。RoomsConfig是为每个预订的房间配置的,它的配置就像用户希望在这个房间里有一台电视,在另一个房间里有一台空调“我不需要对城市和BookingRequest关系产生级联效应”,但您的映射明确说明了这一点。您能告诉我们更多关于您的型号吗?BookingRequest包含一个预订请求:用户信息(姓名、电话、城市)、预订的房间数,我已经在数据库中找到了我需要的所有城市,这就是为什么我不能在城市和BookingRequest之间产生级联效应。RoomsConfig是为每个房间预留的,它的配置,就像用户希望在这个房间里有一台电视,在另一个房间里有一台空调有什么办法可以避免这个解决方案?因为如果一个实体有一系列关系。我必须把它们都放好吗?为什么条令认为实体是新的?@Oscar我不知道为什么会发生这种情况,但是如果你不想在数据库中进行findOneBy,这意味着你需要在数据库中进行另一个查询,你可以尝试使用getReference方法,它只准备实体id的对象,如:$this->\u em->getReference('WhateverBundle:EntityName',$entity\u id);有没有办法避免这种解决方案?因为如果一个实体有一系列关系。我必须设置所有这些关系?为什么条令认为实体是新的?@Oscar我不知道为什么会发生这种情况,但如果你不想让它成为findOneBy,这意味着你需要在数据库中进行另一个查询,你可以尝试使用getReference方法,它只对用实体id重新编写对象,如下所示:$this->\u em->getReference('WhateverBundle:EntityName',$entity\u id);
<?php

namespace Kutiwa\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RoomsConfig
 *
 * @ORM\Table(name="rooms_config")
 * @ORM\Entity(repositoryClass="Kutiwa\PlatformBundle\Repository\RoomsConfigRepository")
 */
class RoomsConfig
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var bool
     *
     * @ORM\Column(name="airConditionner", type="boolean")
     */
    private $airConditionner;

    /**
     * @var bool
     *
     * @ORM\Column(name="wifi", type="boolean")
     */
    private $wifi;

    /**
     * @var bool
     *
     * @ORM\Column(name="balcony", type="boolean")
     */
    private $balcony;

    /**
     * @var string
     *
     * @ORM\Column(name="tv", type="boolean")
     */
    private $tv;

    /**
     * @ORM\ManyToOne(targetEntity="Kutiwa\PlatformBundle\Entity\BookingRequest", inversedBy="roomsConfigs", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $bookingRequest;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }



    /**
     * Set airConditionner
     *
     * @param boolean $airConditionner
     *
     * @return RoomsConfig
     */
    public function setAirConditionner($airConditionner)
    {
        $this->airConditionner = $airConditionner;

        return $this;
    }

    /**
     * Get airConditionner
     *
     * @return boolean
     */
    public function getAirConditionner()
    {
        return $this->airConditionner;
    }

    /**
     * Set wifi
     *
     * @param boolean $wifi
     *
     * @return RoomsConfig
     */
    public function setWifi($wifi)
    {
        $this->wifi = $wifi;

        return $this;
    }

    /**
     * Get wifi
     *
     * @return boolean
     */
    public function getWifi()
    {
        return $this->wifi;
    }

    /**
     * Set balcony
     *
     * @param boolean $balcony
     *
     * @return RoomsConfig
     */
    public function setBalcony($balcony)
    {
        $this->balcony = $balcony;

        return $this;
    }

    /**
     * Get balcony
     *
     * @return boolean
     */
    public function getBalcony()
    {
        return $this->balcony;
    }

    /**
     * Set tv
     *
     * @param boolean $tv
     *
     * @return RoomsConfig
     */
    public function setTv($tv)
    {
        $this->tv = $tv;

        return $this;
    }

    /**
     * Get tv
     *
     * @return boolean
     */
    public function getTv()
    {
        return $this->tv;
    }

    /**
     * Set bookingRequest
     *
     * @param \Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest
     *
     * @return RoomsConfig
     */
    public function setBookingRequest(\Kutiwa\PlatformBundle\Entity\BookingRequest $bookingRequest)
    {
        $this->bookingRequest = $bookingRequest;

        $bookingRequest->addRoomsConfig($this);

        return $this;
    }

    /**
     * Get bookingRequest
     *
     * @return \Kutiwa\PlatformBundle\Entity\BookingRequest
     */
    public function getBookingRequest()
    {
        return $this->bookingRequest;
    }
}
<?php

namespace Kutiwa\PlatformBundle\Form;

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

class BookingRequestType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('arrival', TextType::class)
            ->add('departure', TextType::class)
            ->add('rooms', IntegerType::class)
            ->add('customerName', TextType::class)
            ->add('customerEmail', TextType::class, array('required' => false))
            ->add('customerPhone', TextType::class)
            ->add('destinationCity', EntityType::class, array(
                'choice_label' => 'name',
                'class' => 'KutiwaPlatformBundle:City'
            ))
            ->add('customerCity', EntityType::class, array(
                'choice_label' => 'name',
                'class' => 'KutiwaPlatformBundle:City'
            ));
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Kutiwa\PlatformBundle\Entity\BookingRequest'
        ));
    }

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


}