我正在使用Codeigniter的Doctrine。所以我写了一个库类来一起使用它们。但是我无法访问实体(在使用逆向工程从db创建它们之后)。 Doctrine给出错误:致命错误:未捕获异常'Doctrine \ ORM \ Mapping \ MappingException',消息'Class Actions不是有效实体或映射超类。'
我只是将这种情况的代码添加到库类中并正常工作但速度非常低:
$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 :(得分:1)
解决方案是编辑php.ini文件以关闭eAccelerator:
eaccelerator.enable="0"