2011-09-08 38 views
1

我正在使用Doctrine和Codeigniter。所以我写了一个图书馆班,一起使用它们。但我不能访问实体(在通过反向工程从数据库创建它们之后)。原则给出错误:致命错误:未收集的异常'Doctrine \ ORM \ Mapping \ MappingException'带消息'类操作不是有效的实体或映射的超类。'不是有效的实体或映射类错误

我只是添加此代码,这种情况库班和作品的一切权利,但速度很低

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

我能为这个错误做什么?我产生的实体从DB使用此项功能:

$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"); 

我的行动实体:

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

(编辑)我的图书馆代码:

<?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\DisconnectedClassMetadataFactory, 
    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"); 

      } 

    } 
?> 
+0

因此,您删除因为它很慢,现在你问为什么它不起作用? :-)你需要缓存你的元数据。 – arnaud576875

+0

这是不会缓存我的元数据? $ cache = new ArrayCache; $ config-> setMetadataCacheImpl($ cache); – MAB

+0

如果您安装了APC,则使用ApcCache(您应该,如果您关心性能) – arnaud576875

回答

1

的解决方案是为编辑收盘php.ini文件eAccelerator:

eaccelerator.enable="0" 
+0

MAB请你帮我解决。其实我会做你在回答和评论中提到的所有事情,但仍然陷入同样的​​问题。 –

相关问题