简体   繁体   中英

Doctrine entity class mapping issue showing fatal error

facing this type of issue. I am new in doctrine with codeigniter.

Fatal error: Uncaught exception 'Doctrine\\ORM\\Mapping\\MappingException' with message 'Class "Entity\\Options" is not a valid entity or mapped super class.' in D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\ORM\\Mapping\\MappingException.php:336 Stack trace: #0 D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver.php(89): Doctrine\\ORM\\Mapping\\MappingException::classIsNotAValidEntityOrMappedSuperClass('Entity\\Options') #1 D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\ORM\\Mapping\\ClassMetadataFactory.php(117): Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver->loadMetadataForClass('Entity\\Options', Object(Doctrine\\ORM\\Mapping\\ClassMetadata)) #2 D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory.php(318): Doctrine\\ORM\\Mapping\\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\\ORM\\Mapping\\ClassMetadata), NULL, false, Array) #3 D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\Common\\Persistenc in D:\\xampp\\htdocs\\doctrineGit\\application\\libraries\\Doctrine\\ORM\\Mapping\\MappingException.php on line 336

Here is my entityclass

<?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;
    }

Below is my model class or repository using like this where i am going wrong

<?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();
    }

}

?> 

You didn't write namespace

your entity class

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

and rest of ur code....

your model

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

nd rest of ur code.......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM