Doctrine错误:找不到类'Doctrine \ ORM \ EntityRepository'

时间:2012-07-05 05:28:52

标签: php doctrine-orm composer-php

我是Doctrine的新手,我正在遵循文档中的示例。当我创建一个Repository类(例如UserRepository.php)并尝试扩展EntityRepository类时,我收到以下错误消息:致命错误:在C:\ xampp \ htdocs \ excap中找不到类'Doctrine \ ORM \ EntityRepository'第10行的\ repositories \ UserRepository.php

这是我的Repository类:

use Doctrine\ORM\EntityRepository;

/**
 * Description of UserRepository
 *
 * @author Mario
 */
class UserRepository extends EntityRepository
{ 

我做错了什么? (顺便说一下,我使用Composer安装了Doctrine2)

<?php
//bootstrap_doctrine.php
$isDevMode = true;
use Doctrine\ORM\Tools\Setup;
require_once 'vendor/autoload.php';

$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/entities'), $isDevMode);
$conn = array(
    'driver' => 'pdo_mysql',
    'user' => 'mydbuser',
    'password' => 'mydbpassword',
    'dbname' => 'mydbname'
);

$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
?>

<?php
//boostrap.php
//Entities
require_once 'entities/User.php';
require_once 'entities/Gender.php';
require_once 'entities/AccessPoint.php';

//Repositories
require_once 'repositories/UserRepository.php';

if(!class_exists("Doctrine\Common\Version", FALSE))
{
    require_once 'bootstrap_doctrine.php';
}
?>

<?php
// autoload.php generated by Composer
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
    require __DIR__ . '/composer' . '/ClassLoader.php';
}

return call_user_func(function() {
    $loader = new \Composer\Autoload\ClassLoader();
    $composerDir = __DIR__ . '/composer';

    $map = require $composerDir . '/autoload_namespaces.php';
    foreach ($map as $namespace => $path) {
        $loader->add($namespace, $path);
    }

    $classMap = require $composerDir . '/autoload_classmap.php';
    if ($classMap) {
        $loader->addClassMap($classMap);
    }

    $loader->register();

    return $loader;
});
?>

2 个答案:

答案 0 :(得分:3)

问题解决了。问题出在bootstrap.php文件中。我在加载bootstrap_doctrine.php之前加载了实体;就是这样。

答案 1 :(得分:0)

您是否在命名空间类中放置了命名空间?