恢复值 select 输入相关实体学说 symfony 2

Recover values select imput related entities doctrine symfony 2

我正在尝试根据 Symfony 2 的相关实体创建一个表单。我有不同的实体:Tematica、Personal、Hilo、Consultante、Consulta、Consulta_Asignatura 和 Asignatura。我试图保留我的所有数据,但实体 Hilo Personal 和 Tematica 存在一些问题。 在我的表单中需要显示 select 输入,它应该有所有 "Enunciado" 行,然后在这个 select 输入中恢复 selected 选项的电子邮件。 我会分享我的代码,希望有人能帮助我。

class HiloType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('consultanteemail', new ConsultanteType(), array ('label' => false))
            ->add('personalemail', 'entity', array(
                'label' => 'Personal de Soporte',
                'class' => 'GuiasDocentes\AppBundle\Entity\Personal',
                'property' => 'Email',
                'by_reference' => 'false',
                'query_builder' => function(PersonalRepository $pr) {
                    $query= $pr->createQueryBuilder('u')
                    ;
                    return $query;
                },
                'empty_value' => 'Elige un perfil de consulta:',
                ))
            // ->add('personalemail', new PersonalType(), array ('label' => false))
        ;
    }
 * Personal
 *
 * @ORM\Table(name="personal")
 * @ORM\Entity(repositoryClass="GuiasDocentes\AppBundle\Entity\PersonalRepository")

class Personal
{
    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", length=50, nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $email;

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

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

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

    /* Customized code */
    /**
     * @ORM\OneToMany(targetEntity="GuiasDocentes\AppBundle\Entity\TematicaSoporte", mappedBy="personalEmail")
     * @Assert\Valid()
     */    
    private $tematicasSoporte;

    public function __constructor(){
        $this->tematicasSoporte = new ArrayCollection();
        $this->hilos = new ArrayCollection();
    }

    public function addTematicasSoporte(\GuiasDocentes\AppBundle\Entity\TematicaSoporte $tematicaSoporte){
        $this->tematicasSoporte[] = $tematicaSoporte;
        return $this;
    }    

    public function setTematicasSoporte(\GuiasDocentes\AppBundle\Entity\TematicaSoporte $tematicaSoporte){
        $this->tematicasSoporte[] = $tematicaSoporte;
        return $this;
    }

    public function getTematicasSoporte(){
        return $this->tematicasSoporte;
    }

    /**
     * @ORM\OneToMany(targetEntity="GuiasDocentes\AppBundle\Entity\Hilo", mappedBy="personalemail")
     * @Assert\Valid()
     */    
    private $hilos;

    public function setHilos(Hilo $hilo){
        $this->hilos[] = $hilo;
        return $this;
    }

        public function addHilos(Hilo $hilo){
        $this->hilos[] = $hilo;
        return $this;
    }

    public function getHilos(){
        return $this->hilos;
    }
/**
 * TematicaSoporte
 *
 * @ORM\Table(name="tematica_soporte", indexes={@ORM\Index(name="fk_tematica_soporte_personal1_idx", columns={"personal_email"})})
 * @ORM\Entity(repositoryClass="GuiasDocentes\AppBundle\Entity\TematicaSoporteRepository")
 */
class TematicaSoporte
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

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

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

    /**
     * @var \Personal
     *
     * @ORM\ManyToOne(targetEntity="Personal", inversedBy="tematicasSoporte", cascade={"ALL"})
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="personal_email", referencedColumnName="email")
     * })
     */
    private $personalEmail;
/**
 * Hilo
 *
 * @ORM\Table(name="hilo", indexes={@ORM\Index(name="fk_Hilo_Personal1_idx", columns={"personalEmail"}), @ORM\Index(name="fk_Hilo_Consultante1_idx", columns={"consultanteEmail"})})
 * @ORM\Entity
 */
class Hilo
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \GuiasDocentes\AppBundle\Entity\Personal
     *
     * @ORM\ManyToOne(targetEntity="Personal", inversedBy="hilos", cascade ={"ALL"})
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="personalEmail", referencedColumnName="email")
     * })
     */
    private $personalemail;

    /**
     * @var \GuiasDocentes\AppBundle\Entity\Consultante
     *
     * @ORM\ManyToOne(targetEntity="Consultante", inversedBy="hilos", cascade ={"ALL"} )
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="consultanteEmail", referencedColumnName="email")
     * })
     */
    private $consultanteemail;


    /* Customized code */

    /**
     * @ORM\OneToMany(targetEntity="GuiasDocentes\AppBundle\Entity\Consulta", mappedBy="hiloid")
     * @Assert\Valid()
     */
    private $consultas;

    public function __construct(){

        $this->consultas = new ArrayCollection();
    }

    public function setConsultas (Consulta $consulta){
        $this->hilos[]=$consulta;
    }

    public function addConsulta (\GuiasDocentes\AppBundle\Entity\Consulta $consulta){
        $this->hilos[] = $consulta;
    }


/* End customized code */

与您在此过程中看到的方式相同,我得到 select 由个人 class 的电子邮件生成的字段,您需要显示 Tematica_soporte class 的 Enunciado . 萨克斯

以这种方式在 TematicaSoporte 中添加一个方法就足够了:

public function getEnunciado(){ return $this->getTematicasSoporte()[0]->getEnunciado(); }