Doctrine 2.0.4配置错误? [英] Doctrine 2.0.4 Configuration Error?

查看:88
本文介绍了Doctrine 2.0.4配置错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用教义2.0.4。我不知道这里有什么确切的错误可以帮助吗?

I am using doctrine 2.0.4 .i am not sure where exact wrong here any one can help here?

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

导致:

Error::Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Semantical Error] line 0, col 14 near 'MyProject\Entities\Dept': Error: Class 'MyProject\Entities\Dept' is not defined.

Dept.php in Entities code

<?php


/**
 * Dept
 *
 * @Table(name="dept")
 * @Entity
 */
class Dept
{
    /**
     * @var integer $deptno
     *
     * @Column(name="deptno", type="integer", nullable=false)
     * @Id
     * @GeneratedValue(strategy="IDENTITY")
     */

    private $deptno;

    /**
     * @var string $dname
     *
     * @Column(name="dname", type="string", length=50, nullable=false)
     */
    private $dname;

    /**
     * @var string $location
     *
     * @Column(name="location", type="string", length=50, nullable=false)
     */
    private $location;


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

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

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

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

    /**
     * Get location
     *
     * @return string $location
     */
    public function getLocation()
    {
        return $this->location;
    }
}
    and Proxies class not generated here but Entities is generated...where exact wrong here? 


推荐答案

这不是一个解决方案,但可以尝试使用命令行工具doctrine.php生成代理

It is not a solution but you could try using the commandline tool doctrine.php to generate proxies


php doctrine.php orm:generate-proxies

php doctrine.php orm:generate-proxies

也许你可以从这里找到问题

Maybe you can locate the problem from here

这篇关于Doctrine 2.0.4配置错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆