2014-01-10 3 views
0

나는 사용자 정의 저장소 인스턴스의 목적에 대한 교리 엔티티의 주석 메타 데이터를 읽으려고 해요 :얻기 교리 엔티티 메타 데이터

$userRepository = new \My\Repository\UserRepository($entityManager, $classMetadata); 

$classMetadata을 얻으려면을 나는 다음과 같은 한 :

User 기업 :

namespace My\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity(repositoryClass="My\Repository\UserRepository") 
* @ORM\Table(name="users") 
*/ 
class User { 

    /** 
    * @ORM\Column(name="user_id", type="integer", nullable=false) 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="IDENTITY") 
    */ 
    protected $id; 

    public function getId() 
    { 
     return $this->id; 
    } 

    public function setId($id) 
    { 
     $this->id = $id; 

     return $this; 
    } 

} 

UserRepository :

namespace My\Repository; 

use Doctrine\ORM\EntityRepository; 

class UserRepository extends EntityRepository { 

} 

내 주요 스크립트

require '../vendor/autoload.php'; 

use Doctrine\ORM\Tools\Setup; 
use Doctrine\ORM\EntityManager; 

$paths = array('../src/My/Entity'); 
$isDevMode = TRUE; 

// the connection configuration 
$dbParams = array(
    'driver' => 'pdo_mysql', 
    'dbname' => 'mydb', 
    'user'  => 'myuser', 
    'password' => 's3cr3t', 
); 

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); 
$entityManager = EntityManager::create($dbParams, $config); 

$classMetadata = $entityManager->getClassMetadata('\My\Entity\User'); 

하지만 다음과 같은 오류가 계속 :

PHP Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class "My\Entity\User" is not a valid entity or mapped super class.' in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:216 

내가 놓치고 무엇을?

업데이트 : 나는 다음과 같은 노력했습니다

:

$userRepository = $entityManager->getRepository('\My\Entity\User'); 

하지만이 같은 오류를 받고 있어요.

UPDATE 2 : 교리 자습서 [1]에 설명 된대로

나는 bootstrap.phpcli-config.php 파일을 설정하고 난 지금 bin/doctrine 명령 행 유틸리티를 실행할 수 있습니다. 흥미로운 결과 :

bin/doctrine orm:validate-schema 

출력 :

[Mapping] OK - The mapping files are correct. 
[Database] OK - The database schema is in sync with the mapping files. 

하지만 수행 할 때

bin/doctrine orm:info 

출력 :

[Exception]                                            
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors. 

어떤 아이디어가?

[1] http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html

답변

관련 문제