2011-05-04 2 views
2

doctrine 2.0.4 .i를 사용하고 있습니다. 여기에 정확한 오류가있는 곳을 정확히 모르겠습니까? 결과Doctrine 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, 
    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? 
+4

어떤 오류가 발생하고 있습니까? – Cobby

+0

프록시 클래스는 genarated되지 않습니다 ... 내가 지금 뭐하고 있는거야? – Karthik

+0

당신의 스크립트는 어떤 결과물이라도 생성 할 것입니다, 단지 EntityManager의 인스턴스입니다. 'var_dump ($ em);'를 맨 아래에 추가하고 어떤 일이 일어 났는지 알려주세요. – Cobby

답변

1

그것은 해결책이 아니다 그러나 당신은 아마 당신이에서 문제를 찾을 수 있습니다 프록시

php doctrine.php orm:generate-proxies

를 생성하는 명령 행 도구의 doctrine.php를 사용하여 시도 할 수 여기

+0

no.here 엔티티를 이미 생성했습니다 ... – Karthik

+0

오류 : 치명적 오류 : 'Doctrine \ ORM \ Query \ QueryException'메시지와 함께 '캐치'오류가 발생했습니다 : 'MyProject \ Entities \ Dept' : 오류 : 'MyProject \ Entities \ Dept'클래스가 정의되지 않았습니다. – Karthik

+0

사용중인 엔티티 코드 및 디렉토리 구조에 대한 추가 정보를 제공 할 수 있습니까? – roelio

0

나는 다음 줄로 생각한다 :

$classLoader = new ClassLoader('Entities',$lib1); 

는 같아야

$classLoader = new ClassLoader('MyProject\Entities',$lib1); 

첫번째 파라미터는 자동으로 적재 클래스 네임 때문에.

+0

이미 사용하고 있지 않습니다. .. – Karthik