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


Symfony2 - Doctrine exception: class used in the discriminator map does not exist

我正在使用带有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。

当我加载fixture时,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();
        }
}

这是实体Sue_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');
}

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

将文件名和类名更改为SuenoVideoSuenoFoto