Doctrine错误:未找到类'Doctrine\ORM\EntityRepository' [英] Doctrine error: Class 'Doctrine\ORM\EntityRepository' not found

查看:611
本文介绍了Doctrine错误:未找到类'Doctrine\ORM\EntityRepository'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Doctrine的新人,我遵循文档中的示例。当我创建一个Repository类(例如UserRepository.php),我试图扩展EntityRepository类,我得到这个错误消息:致命错误:类'Doctrine\ORM\EntityRepository'没有找到C:\xampp\\ \\ htdocs \excap \repositories\UserRepository.php on line 10

I'm new in Doctrine, I'm following the examples in the documentation. When I create a Repository class (e.g. UserRepository.php) and I try to extend EntityRepository class I get this error message: Fatal error: Class 'Doctrine\ORM\EntityRepository' not found in C:\xampp\htdocs\excap\repositories\UserRepository.php on line 10

这是我的Repository类:

This is my Repository class:

use Doctrine\ORM\EntityRepository;

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

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

What am I doing wrong? (by the way, I installed Doctrine2 using Composer)

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


推荐答案

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

Problem solved. The problem was in the bootstrap.php file. I was loading the entities before loading the bootstrap_doctrine.php; that's all.

这篇关于Doctrine错误:未找到类'Doctrine\ORM\EntityRepository'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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