Symfony2 - Doctrine异常:鉴别器映射中使用的类不存在

时间:2013-11-26 22:50:38

标签: php symfony inheritance doctrine-orm mappingexception

我正在使用带有Doctrine的Symfony2,当我从我的控制器查询时出现下一个错误(当我调用该页面时它出现在导航器中):

Entity class 'Bdreamers\SuenoBundle\Entity\Sueno_video' used in the discriminator map of class 'Bdreamers\SuenoBundle\Entity\Sueno' does not exist.

我有一个名为“Sueno”的实体(超类)和两个从它扩展的实体(子类):Sueno_foto和Sueno_video。

当我加载灯具时,Doctrine完美运行并且没有任何问题填充数据库,正确填充“Sueno”表中的鉴别器字段“tipo”。它还正确填充了继承的实体表“Sueno_video”,引入了“Sueno”的ID和“Sueno_video”的专属字段

这是“Sueno”实体文件的代码:

<?php

namespace Bdreamers\SuenoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table()
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="tipo", type="string")
 * @ORM\DiscriminatorMap({"sueno" = "Sueno", "video" = "Sueno_video", "foto" = "Sueno_foto"})
 */
class Sueno
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario")
     **/
    private $usuario;

    /**
     * @ORM\ManyToMany(targetEntity="Bdreamers\SuenoBundle\Entity\Tag", inversedBy="suenos")
     * @ORM\JoinTable(name="suenos_tags")
     **/
    private $tags;

    /**
     * @ORM\ManyToMany(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario", mappedBy="suenos_sigue")
     * @ORM\JoinTable(name="usuarios_siguen")
     **/
    private $usuariosSeguidores;

    /**
     * @ORM\ManyToMany(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario", mappedBy="suenos_colabora")
     * @ORM\JoinTable(name="usuarios_colaboran")
     **/
    private $usuariosColaboradores;


    /**
     * @var \DateTime
     *
     * @ORM\Column(name="fecha_subida", type="datetime")
     */
    private $fechaSubida;

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

    /**
     * @var string
     *
     * @ORM\Column(name="que_pido", type="string", length=140)
     */
    private $quePido;

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


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

    /**
     * Set usuario
     *
     * @param string $usuario
     * @return Sueno
     */
    public function setUsuario($usuario)
    {
        $this->usuario = $usuario;

        return $this;
    }

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

    public function getTags()
    {
        return $this->tags;
    }

    /**
     * Set usuariosSeguidores
     *
     * @param string $usuariosSeguidores
     * @return Sueno
     */
    public function setUsuariosSeguidores($usuariosSeguidores)
    {
        $this->usuariosSeguidores = $usuariosSeguidores;

        return $this;
    }

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

    /**
     * Set usuariosColaboradores
     *
     * @param string $usuariosColaboradores
     * @return Sueno
     */
    public function setUsuariosColaboradores($usuariosColaboradores)
    {
        $this->usuariosColaboradores = $usuariosColaboradores;

        return $this;
    }

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


    /**
     * Set fechaSubida
     *
     * @param \DateTime $fechaSubida
     * @return Sueno
     */
    public function setFechaSubida($fechaSubida)
    {
        $this->fechaSubida = $fechaSubida;

        return $this;
    }

    /**
     * Get fechaSubida
     *
     * @return \DateTime 
     */
    public function getFechaSubida()
    {
        return $this->fechaSubida;
    }

    /**
     * Set titulo
     *
     * @param string $titulo
     * @return Sueno
     */
    public function setTitulo($titulo)
    {
        $this->titulo = $titulo;

        return $this;
    }

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

    /**
     * Set quePido
     *
     * @param string $quePido
     * @return Sueno
     */
    public function setQuePido($quePido)
    {
        $this->quePido = $quePido;

        return $this;
    }

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

    /**
     * Set texto
     *
     * @param string $texto
     * @return Sueno
     */
    public function setTexto($texto)
    {
        $this->texto = $texto;

        return $this;
    }

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

    public function __construct() {
        $this->usuariosColaboradores = new \Doctrine\Common\Collections\ArrayCollection();
        $this->usuariosSeguidores = new \Doctrine\Common\Collections\ArrayCollection();
        $this->tags = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

这是实体Sueno_video的代码:

<?php

namespace Bdreamers\SuenoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table()
 * @ORM\Entity
 */
class Sueno_video extends Sueno
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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


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


    /**
     * Set linkVideo
     *
     * @param string $linkVideo
     * @return Sueno_video
     */
    public function setLinkVideo($linkVideo)
    {
        $this->linkVideo = $linkVideo;

        return $this;
    }

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

最后是控制器中的代码:

public function homeAction()
{

    $em = $this->getDoctrine()->getManager();

    $suenos = $em->getRepository('SuenoBundle:Sueno')->findOneBy(array(
        'fechaSubida' => new \DateTime('now -2 days')
        ));

    return $this->render('EstructuraBundle:Home:home_registrado.html.twig');
}

1 个答案:

答案 0 :(得分:2)

自动加载器无法将这些类名称解析为文件路径,因此无法找到您的类。

将文件和类名更改为SuenoVideoSuenoFoto