开发者

is not a valid entity or mapped class Error

I'm using Doctrine with Codeigniter. So i write a library class for using them together. But i cant access entities (after creating them from db with reverse-engineering). Doctrine gives error: Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class Actions is not a valid entity or mapped super class.'

I just add this code for this situation to library class and works everything right but speed is very low:

    $this->em->getConfiguration()
             ->setMetadataDriverImpl(
                new DatabaseDriver(
                        $this->em->getConnection()->getSchemaManager()
                )
    );

What can i do for this error? I generated entities from DB with this function:

    $cmf = new DisconnectedClassMetadataFactory();
    $cmf->setEntityManager($this->em);
    $metadata = $cmf->getAllMetadata();
    $generator = new EntityGenerator();

    $generator->setUpdateEntityIfExists(true);
    $generator->setGenerateStubMethods(true);
    $generator->setGenerateAnnotations(true);
    $generator->generate($metadata, APPPATH."models/entities");

My Action entity:

<?php



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

    /**
     * @var string $name
     *
     * @Column(name="name", type="string", length=45, nullable=false)
     */
    public $name;

    /**
     * @var string $nameSafe
     *
     * @Column(name="name_safe", type="string", length=45, nullable=false)
     */
    public $nameSafe;


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

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

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

    /**
     * Set nameSafe
     *
     * @param string $nameSafe
     */
    public function setNameSafe($nameSafe)
    {
        $this->nameSafe = $nameSafe;
    }

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

(edit) My Library Code:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use Doctrine\Common\ClassLoader,
    Doctrine\ORM\Configuration,
    Doctrine\ORM\EntityManager,
    Doctrine\Common\Cache\ArrayCache,
    Doctrine\DBAL\Logging\EchoSQLLogger,
    Doctrine\ORM\Mapping\Driver\DatabaseDriver,
    Doctrine\ORM\Tools\DisconnectedClassMeta开发者_如何学PythondataFactory,
    Doctrine\ORM\Tools\EntityGenerator;

    /**
     * CodeIgniter Doctrine Class
     *
     * initializes basic doctrine settings and act as doctrine object
     *
     * @author  Mehmet Aydın Bahadır
     * @link    http://www.biberltd.com/
     */
    class Doctrine {

          /**
           * @var EntityManager $em
           */
            public $em = null;

          /**
           * constructor
           */
          public function __construct()
          {
            // load database configuration from CodeIgniter
            require APPPATH.'config/database.php';

            // Set up class loading. You could use different autoloaders, provided by your favorite framework,
            // if you want to.
            require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';

            $doctrineClassLoader = new ClassLoader('Doctrine',  APPPATH.'third_party');
            $doctrineClassLoader->register();
            $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" ));
            $entitiesClassLoader->register();
            $proxiesClassLoader = new ClassLoader('proxies', APPPATH.'models');
            $proxiesClassLoader->register();

            // Set up caches
            $config = new Configuration;
            $cache = new ArrayCache;
            $config->setMetadataCacheImpl($cache);
            $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/entities'));
            $config->setMetadataDriverImpl($driverImpl);
            $config->setQueryCacheImpl($cache);

            // Proxy configuration
            $config->setProxyDir(APPPATH.'models/proxies');
            $config->setProxyNamespace('Proxies');

            // Set up logger
            //$logger = new EchoSQLLogger;
            //$config->setSQLLogger($logger);

            $config->setAutoGenerateProxyClasses( TRUE );
            // Database connection information
            $connectionOptions = array(
                'driver' => 'pdo_mysql',
                'user' =>     $db['default']['username'],
                'password' => $db['default']['password'],
                'host' =>     $db['default']['hostname'],
                'dbname' =>   $db['default']['database']
            );

            // Create EntityManager
            $this->em = EntityManager::create($connectionOptions, $config);
//          $this->generate_classes();

          }

          /**
           * generate entity objects automatically from mysql db tables
           * @return none
           */
          public function generate_classes(){     

//            $this->em->getConfiguration()
//                     ->setMetadataDriverImpl(
//                        new DatabaseDriver(
//                                $this->em->getConnection()->getSchemaManager()
//                        )
//            );

            $cmf = new DisconnectedClassMetadataFactory();
            $cmf->setEntityManager($this->em);
            $metadata = $cmf->getAllMetadata();
            $generator = new EntityGenerator();

            $generator->setUpdateEntityIfExists(true);
            $generator->setGenerateStubMethods(true);
            $generator->setGenerateAnnotations(true);
            $generator->generate($metadata, APPPATH."models/entities");

          }

    }
?>


Solution is editing php.ini file for closing eAccelerator:

eaccelerator.enable="0"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜