当存在另一个中间表时,如何从表中获取数据

时间:2019-05-10 09:53:36

标签: symfony4

我在艺术家和约会表之间有很多关系。我想检索艺术家的类别,该艺术家的类别与艺术家类别表之间的关系是一对多的(一个类别可以有多个艺术家)。当我尝试从树枝视图访问它时,会收到以下消息:属性“ category”或方法“ category()”,“ getcategory()” /“ iscategory()” /“ hascategory()”之一“或” __call()”已存在,并且在“ Doctrine \ ORM \ PersistentCollection”类中具有公共访问权限。

{% extends 'base.html.twig' %}

{% block body %}
    <section id="container">
        <div class="bandeau">
            <div class="icone">
                <div>
                    <img src="../img/icoLieuDetail.png" alt="lieu" />
                    <p>{{ appointment.place.title }}</p>
                </div>
                <div>
                    <img src="../img/icoDateDetail.png" alt="date" />
                    <p>{{ appointment.beginAt | localizeddate('none', 'none', null, null, 'EEE') }} {{ appointment.endAt | date('d')}} {{ appointment.beginAt | localizeddate('none', 'none', null, null, 'MMM')}}</p>
                </div>
                <div>
                    <img src="../img/icoCatDetail.png" alt="domaine artistique" />
                    <p>{{ appointment.artist.category.category }}</p>

                </div>
            </div>
            <div class="btn-container">
                <button class="button">Intéressé</button>
            </div>
        </div>
        <article class="box">
            <div class="element">
                <img src="../img/evenement_1_p.jpg" alt="image évènement" width="600px" height="400px" />
            </div>
            <div class="article">
                <h2>{{ appointment.title }}</h2>
                <p>{{ appointment.description }}</p>
                <div class="reseaux">
                    <img src="../img/icoWeb.png" alt="lien site web">
                    <img src="../img/icoFb.png" alt="lien page facebook">
                    <img src="../img/icoInsta.png" alt="lien compte instagram">
                </div>
            </div>
        </article>
    </section>
{% endblock %}

class Appointment
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100, nullable=true)
     */
    private $title;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $begin_at;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $end_at;

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

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

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

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $counter;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Place", inversedBy="appointments")
     */
    private $place;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Artist", inversedBy="appointments")
     */
    private $artist;

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

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

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(?string $title): self
    {
        $this->title = $title;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;

        return $this;
    }

    public function getBeginAt(): ?\DateTimeInterface
    {
        return $this->begin_at;
    }

    public function setBeginAt(?\DateTimeInterface $begin_at): self
    {
        $this->begin_at = $begin_at;

        return $this;
    }

    public function getEndAt(): ?\DateTimeInterface
    {
        return $this->end_at;
    }

    public function setEndAt(?\DateTimeInterface $end_at): self
    {
        $this->end_at = $end_at;

        return $this;
    }

    public function getWeb(): ?string
    {
        return $this->web;
    }

    public function setWeb(?string $web): self
    {
        $this->web = $web;

        return $this;
    }

    public function getFacebook(): ?string
    {
        return $this->facebook;
    }

    public function setFacebook(?string $facebook): self
    {
        $this->facebook = $facebook;

        return $this;
    }

    public function getInstagram(): ?string
    {
        return $this->instagram;
    }

    public function setInstagram(?string $instagram): self
    {
        $this->instagram = $instagram;

        return $this;
    }

    public function getCounter(): ?int
    {
        return $this->counter;
    }

    public function setCounter(?int $counter): self
    {
        $this->counter = $counter;

        return $this;
    }

    public function getPlace(): ?Place
    {
        return $this->place;
    }

    public function setPlace(?Place $place): self
    {
        $this->place = $place;

        return $this;
    }

    /**
     * @return Collection|Artist[]
     */
    public function getArtist(): Collection
    {
        return $this->artist;
    }

    public function addArtist(Artist $artist): self
    {
        if (!$this->artist->contains($artist)) {
            $this->artist[] = $artist;
        }

        return $this;
    }

    public function removeArtist(Artist $artist): self
    {
        if ($this->artist->contains($artist)) {
            $this->artist->removeElement($artist);
        }

        return $this;
    }
}

class Artist
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

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

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(type="string", length=50, nullable=true)
     */
    private $phone_nb;

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

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

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

    /**
     * @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="artist", cascade={"persist", "remove"})
     */
    private $user;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="artists")
     */
    private $category;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Appointment", mappedBy="artist")
     */
    private $appointments;

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

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;

        return $this;
    }

    //---------------methode toString
    public function __toString()
    {
        return $this->getName();
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;

        return $this;
    }

    public function getPhoneNb(): ?string
    {
        return $this->phone_nb;
    }

    public function setPhoneNb(?string $phone_nb): self
    {
        $this->phone_nb = $phone_nb;

        return $this;
    }

    public function getWeb(): ?string
    {
        return $this->web;
    }

    public function setWeb(?string $web): self
    {
        $this->web = $web;

        return $this;
    }

    public function getFacebook(): ?string
    {
        return $this->facebook;
    }

    public function setFacebook(?string $facebook): self
    {
        $this->facebook = $facebook;

        return $this;
    }

    public function getInstagram(): ?string
    {
        return $this->instagram;
    }

    public function setInstagram(?string $instagram): self
    {
        $this->instagram = $instagram;

        return $this;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getCategory(): ?Category
    {
        return $this->category;
    }

    public function setCategory(?Category $category): self
    {
        $this->category = $category;

        return $this;
    }

    /**
     * @return Collection|Appointment[]
     */
    public function getAppointments(): Collection
    {
        return $this->appointments;
    }

    public function addAppointment(Appointment $appointment): self
    {
        if (!$this->appointments->contains($appointment)) {
            $this->appointments[] = $appointment;
            $appointment->addArtist($this);
        }

        return $this;
    }

    public function removeAppointment(Appointment $appointment): self
    {
        if ($this->appointments->contains($appointment)) {
            $this->appointments->removeElement($appointment);
            $appointment->removeArtist($this);
        }

        return $this;
    }
}

0 个答案:

没有答案