编辑标签将使用EasyAdminBundle更改Symfony4中的表单类型

问题描述 投票:0回答:2

首先,我是Symfony4的法国初学者,其次,我已经在Symfony文档中搜索过,问过一些朋友,打电话给我妈妈。

我正在使用Edit / New Entity表单上的EasyAdminBundle。

我必须更改我的实体的标签,但当我这样做时,我的表单类型正在改变。

这是编辑前我的视图的图片:

我想将'id_equipe'更改为'Domicile(home for english)'和id_equipe_equipes更改为'exterieur(Visitors)'

所以,当我尝试这个:

 fields:
     - { property: 'id_equipe', label: equipe_domicile}
     - { property: 'id_equipe_equipes', label: equipe_extérieur}

属性的类型正在更改为TextArea,我不知道为什么。

我试着把这样的新类型:

 - { property: 'id_equipe', label: equipe_domicile, type: 'choice'}

但我的select是空白的,我不能选择任何东西。

这就是我得到的:

谢谢你们

Ps:抱歉十岁的英语

symfony types label symfony4 easyadmin
2个回答
0
投票

这是我的Matchs实体。

<?php

namespace App\Entity;

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

/**
 * Matchs
 *
 * @ORM\Table(name="matchs", indexes={@ORM\Index(name="MATCHS_EQUIPES1_FK", columns={"ID_EQUIPE_EQUIPES"}), @ORM\Index(name="MATCHS_EQUIPES_FK", columns={"ID_EQUIPE"}), @ORM\Index(name="MATCHS_JOURNEE0_FK", columns={"ID_JOURNEE"})})
 * @ORM\Entity
 */
class Matchs
{
    /**
     * @var int
     *
     * @ORM\Column(name="ID_MATCHS", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $idMatchs;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="DATE_MATCHS", type="datetime", nullable=false)
     */
    private $dateMatchs;

    /**
     * @var string|null
     *
     * @ORM\Column(name="RESUME_MATCHS", type="text", length=65535, nullable=true)
     */
    private $resumeMatchs;

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

    /**
     * @var int
     *
     * @ORM\Column(name="SCORE_EQUIPE1", type="integer", nullable=false)
     */
    private $scoreEquipe1;

    /**
     * @var int
     *
     * @ORM\Column(name="SCORE_EQUIPE2", type="integer", nullable=false)
     */
    private $scoreEquipe2;

    /**
     * @var \Equipes
     *
     * @ORM\ManyToOne(targetEntity="Equipes")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ID_EQUIPE_EQUIPES", referencedColumnName="ID_EQUIPE")
     * })
     */
    private $idEquipeEquipes;

    /**
     * @var \Equipes
     *
     * @ORM\ManyToOne(targetEntity="Equipes")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ID_EQUIPE", referencedColumnName="ID_EQUIPE")
     * })
     */
    private $idEquipe;

    /**
     * @var \Journee
     *
     * @ORM\ManyToOne(targetEntity="Journee")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ID_JOURNEE", referencedColumnName="ID_JOURNEE")
     * })
     */
    private $idJournee;

    /**
     * @var \Doctrine\Common\Collections\Collection
     *
     * @ORM\ManyToMany(targetEntity="JoueursEquipe", inversedBy="idMatchs")
     * @ORM\JoinTable(name="jouer",
     *   joinColumns={
     *     @ORM\JoinColumn(name="ID_MATCHS", referencedColumnName="ID_MATCHS")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="ID_JOUEUR_EQUIPE", referencedColumnName="ID_JOUEUR_EQUIPE")
     *   }
     * )
     */
    private $idJoueurEquipe;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->idJoueurEquipe = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getIdMatchs()
    {
        return $this->idMatchs;
    }

    public function setIdMatchs(int $idMatchs)
    {
        $this->idMatchs = $idMatchs;

        return $this;
    }

    /**
     * Get the value of dateMatchs
     *
     * @return  \DateTime
     */ 
    public function getDateMatchs()
    {
        return $this->dateMatchs;
    }

    /**
     * Set the value of dateMatchs
     *
     * @param  \DateTime  $dateMatchs
     *
     * @return  self
     */ 
    public function setDateMatchs(\DateTime $dateMatchs)
    {
        $this->dateMatchs = $dateMatchs;

        return $this;
    }

    /**
     * Get the value of resumeMatchs
     *
     * @return  string|null
     */ 
    public function getResumeMatchs()
    {
        return $this->resumeMatchs;
    }

    /**
     * Set the value of resumeMatchs
     *
     * @param  string|null  $resumeMatchs
     *
     * @return  self
     */ 
    public function setResumeMatchs($resumeMatchs)
    {
        $this->resumeMatchs = $resumeMatchs;

        return $this;
    }

    /**
     * Get the value of scoreEquipe1
     *
     * @return  int
     */ 
    public function getScoreEquipe1()
    {
        return $this->scoreEquipe1;
    }

    /**
     * Set the value of scoreEquipe1
     *
     * @param  int  $scoreEquipe1
     *
     * @return  self
     */ 
    public function setScoreEquipe1(int $scoreEquipe1)
    {
        $this->scoreEquipe1 = $scoreEquipe1;

        return $this;
    }

    /**
     * Get the value of scoreEquipe2
     *
     * @return  int
     */ 
    public function getScoreEquipe2()
    {
        return $this->scoreEquipe2;
    }

    /**
     * Set the value of scoreEquipe2
     *
     * @param  int  $scoreEquipe2
     *
     * @return  self
     */ 
    public function setScoreEquipe2(int $scoreEquipe2)
    {
        $this->scoreEquipe2 = $scoreEquipe2;

        return $this;
    }

    /**
     * Get the value of idEquipeEquipes
     *
     * @return  \Equipes
     */ 
    public function getIdEquipeEquipes()
    {
        return $this->idEquipeEquipes;
    }

    /**
     * Set the value of idEquipeEquipes
     *
     * @param  \Equipes  $idEquipeEquipes
     *
     * @return  self
     */ 
    public function setIdEquipeEquipes(\Equipes $idEquipeEquipes)
    {
        $this->idEquipeEquipes = $idEquipeEquipes;

        return $this;
    }

    /**
     * Get the value of idEquipe
     *
     * @return  \Equipes
     */ 
    public function getIdEquipe()
    {
        return $this->idEquipe;
    }

    /**
     * Set the value of idEquipe
     *
     * @param  \Equipes  $idEquipe
     *
     * @return  self
     */ 
    public function setIdEquipe(\Equipes $idEquipe)
    {
        $this->idEquipe = $idEquipe;

        return $this;
    }
    
    public function __toString()
    {
        return $this->nomEquipe;
    }

    /**
     * Get the value of idJournee
     *
     * @return  \Journee
     */ 
    public function getIdJournee()
    {
        return $this->idJournee;
    }

    /**
     * Set the value of idJournee
     *
     * @param  \Journee  $idJournee
     *
     * @return  self
     */ 
    public function setIdJournee(\Journee $idJournee)
    {
        $this->idJournee = $idJournee;

        return $this;
    }

    public function getTitreMatch(): ?string
    {
        return $this->titreMatch;
    }

    public function setTitreMatch(string $titreMatch): self
    {
        $this->titreMatch = $titreMatch;

        return $this;
    }

    /**
     * Get the value of idJoueurEquipe
     *
     * @return  \Doctrine\Common\Collections\Collection
     */ 
    public function getIdJoueurEquipe()
    {
        return $this->idJoueurEquipe;
    }

    /**
     * Set the value of idJoueurEquipe
     *
     * @param  \Doctrine\Common\Collections\Collection  $idJoueurEquipe
     *
     * @return  self
     */ 
    public function setIdJoueurEquipe(\Doctrine\Common\Collections\Collection $idJoueurEquipe)
    {
        $this->idJoueurEquipe = $idJoueurEquipe;

        return $this;
    }

    public function addIdJoueurEquipe(JoueursEquipe $idJoueurEquipe): self
    {
        if (!$this->idJoueurEquipe->contains($idJoueurEquipe)) {
            $this->idJoueurEquipe[] = $idJoueurEquipe;
        }

        return $this;
    }

    public function removeIdJoueurEquipe(JoueursEquipe $idJoueurEquipe): self
    {
        if ($this->idJoueurEquipe->contains($idJoueurEquipe)) {
            $this->idJoueurEquipe->removeElement($idJoueurEquipe);
        }

        return $this;
    }
}

0
投票

所以,看,如果我理解正确 - id_equipe是外部实体的关键。所以,这样,为了让它工作 - 你需要使用type: 'entity'并添加type_options选项,类似的东西:

- { property: 'id_equipe', label: 'Domicile', type: 'entity', type_options: { class: 'App\Entity\Equipe', multiple: true } }

更新:

所以,由于讨论发现问题是在属性命名。是property: 'idEquipe'而不是property: 'id_equipe'的权利。因此,属性名称必须与实体中的属性名称相同,而不是数据库中字段的名称。

© www.soinside.com 2019 - 2024. All rights reserved.