Php 条令2.0.4配置错误?
我使用的是教义2.0.4。我不确定这里到底哪里错了,有人能帮上忙吗Php 条令2.0.4配置错误?,php,doctrine,doctrine-orm,Php,Doctrine,Doctrine Orm,我使用的是教义2.0.4。我不确定这里到底哪里错了,有人能帮上忙吗 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); use Doctrine\Common\ClassLoader, Doctrine\ORM\Configuration, Doctrine\ORM\EntityManager, Doctrine\ORM\Tools\EntityGenerator, Doctri
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\ORM\Tools\EntityGenerator,
Doctrine\Common\Cache\ApcCache,
Entities\User,Entity\Address;
$RootPath = $_SERVER['DOCUMENT_ROOT'] . '/';
require $RootPath.'doctrine2/Doctrine/Common/ClassLoader.php';
$lib = $RootPath.'doctrine2/';
$lib1 = $RootPath.'MyProject/';
$classLoader = new ClassLoader('Doctrine',$lib);
$classLoader->register();
$classLoader = new ClassLoader('Entities',$lib1);
$classLoader->register();
$classLoader = new ClassLoader('Proxies',$lib1);
$classLoader->register();
$config = new Configuration;
$cache= new ApcCache;
$driverImpl = $config->newDefaultAnnotationDriver($lib1.'Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir($lib1.'Proxies');
$config->setProxyNamespace('MyProject\Proxies');
$config->setAutoGenerateProxyClasses(true);
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'test',
'user' => 'abc',
'password' => '123321',
'host' => '127.0.0.1');
$em = EntityManager::create($connectionOptions, $config);
echo "<pre>";
print_r($em);
// custom datatypes (not mapped for reverse engineering)
/*$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
*/
// fetch metadata
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager()
);
$em->getConfiguration()->setMetadataDriverImpl($driver);
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
$cmf->setEntityManager($em);
$classes = $driver->getAllClassNames();
$metadata = $cmf->getAllMetadata();
$generator = new EntityGenerator();
$generator->setUpdateEntityIfExists(true);
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, $lib1 . 'Entities');
echo 'Done';
$q = $em->createQuery("select u from MyProject\Entities\Dept u ");
$users = $q->getResult();
?>
导致:
$classLoader = new ClassLoader('Entities',$lib1);
Error::致命错误:未捕获异常“条令\ORM\Query\QueryException”,消息“[Semantic Error]第0行,第14列“MyProject\Entities\Dept”附近”:错误:未定义类“MyProject\Entities\Dept”。
实体代码中的Dept.php
这不是一个解决方案,但您可以尝试使用命令行工具doctor.php生成代理
php.php orm:生成代理
也许你可以从这里找到问题所在我认为这行有:
$classLoader = new ClassLoader('MyProject\Entities',$lib1);
应该是:
因为第一个参数是自动加载类的名称空间。代理未生成的类。我现在做什么?您的脚本将创建任何输出,只是EntityManager的一个实例。添加var\u转储($em)代码>到底部,告诉我发生了什么。你的代理文件夹可写吗?我很确定Doctrine只会根据需要生成代理。现在生成实体,但不会生成代理…这是在您的本地主机上吗?能否确认已安装APC?否。此处已生成实体…错误::致命错误:未捕获异常“条令\ORM\Query\QueryException”,消息为“[Semantical Error]第0行,第14列“MyProject\Entities\Dept”附近:错误:未定义类“MyProject\Entities\Dept”。能否提供有关您正在使用的实体代码和目录结构的更多信息?在此处添加了我的实体部门代码?似乎您尚未在实体代码中声明命名空间,应该类似于namespace MyProject\enities
$classLoader = new ClassLoader('MyProject\Entities',$lib1);