Doctrine实体类映射问题显示致命错误

时间:2015-02-23 11:21:18

标签: php codeigniter orm doctrine-orm

面对这类问题。我是codeigniter的新学说。

  

致命错误:未捕获的异常   '学说\ ORM \映射\ MappingException'与消息'类   "实体\选项"不是有效的实体或映射的超类。'在   d:\ XAMPP \ htdocs中\ doctrineGit \应用\库\学说\ ORM \映射\ MappingException.php:336   堆栈跟踪:#0   d:\ XAMPP \ htdocs中\ doctrineGit \应用\库\学说\ ORM \映射\驱动\ AnnotationDriver.php(89):   教义\ ORM \映射\ MappingException :: classIsNotAValidEntityOrMappedSuperClass('实体\选项')    #1 D:\ xampp \ htdocs \ doctrineGit \ application \ libraries \ Doctrine \ ORM \ Mapping \ ClassMetadataFactory.php(117):   教义\ ORM \映射\驱动\ AnnotationDriver-> loadMetadataForClass('实体\选项&#39 ;,   对象(Doctrine \ ORM \ Mapping \ ClassMetadata))#2    d:\ XAMPP \ htdocs中\ doctrineGit \应用\库\学说\共同\持久性\映射\ AbstractClassMetadataFactory.php(318):   教义\ ORM \映射\ ClassMetadataFactory-> doLoadMetadata(对象(学说\ ORM \映射\ ClassMetadata),   NULL,false,Array)#3   d:\ XAMPP \ htdocs中\ doctrineGit \程序\ \库学说\ COMMON \ Persistenc   在   d:\ XAMPP \ htdocs中\ doctrineGit \应用\库\学说\ ORM \映射\ MappingException.php   在336行

这是我的实体类

<?php

use Doctrine\ORM\Mapping as ORM;


/**
 * Options
 *
 * @ORM\Table(name="options")
 * @ORM\Entity
 */
class Options
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

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

    /**
     * @var boolean
     *
     * @ORM\Column(name="active", type="boolean", nullable=true)
     */
    private $active = '1';


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

    /**
     * Set name
     *
     * @param string $name
     * @return Options
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

下面是我的模型类或存储库,使用这样的地方我错了

<?php
use models\Entity\Options;

class OptionsRepository extends CI_Model {

    public $em;

    public function __construct() {
        parent::__construct();
        $this->load->library('doctrine');
        $this->em = $this->doctrine->em;
    }

    public function getOptions() {
        $dql = "SELECT o FROM \Entity\Options o";

         $query = $this->em->createQuery($dql);

        return $query->getResult();
    }

}

?> 

1 个答案:

答案 0 :(得分:0)

你没有写命名空间

您的实体类

 <?php namespace Entity; use Doctrine\ORM\Mapping as ORM;.......?>

以及其余的代码......

您的模型

<?php namespace Entity; use models\Entity\Options;.........?>

其余的代码.......