Doctrine error: Class #39;DoctrineORMEntityRepository#39; not found(教义错误:找不到类 DoctrineORMEntityRepository)
问题描述
我是 Doctrine 的新手,我正在关注文档中的示例.当我创建一个 Repository 类(例如 UserRepository.php)并尝试扩展 EntityRepository 类时,我收到以下错误消息:Fatal error: Class 'DoctrineORMEntityRepository' not found in C:xampphtdocsexcap epositoriesUserRepository.php 第 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 'DoctrineORMEntityRepository' not found in C:xampphtdocsexcap epositoriesUserRepository.php on line 10
这是我的存储库类:
use DoctrineORMEntityRepository;
/**
* 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 DoctrineORMToolsSetup;
require_once 'vendor/autoload.php';
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/entities'), $isDevMode);
$conn = array(
'driver' => 'pdo_mysql',
'user' => 'mydbuser',
'password' => 'mydbpassword',
'dbname' => 'mydbname'
);
$entityManager = DoctrineORMEntityManager::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("DoctrineCommonVersion", 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 ComposerAutoloadClassLoader();
$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.
这篇关于教义错误:找不到类 'DoctrineORMEntityRepository'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:教义错误:找不到类 'DoctrineORMEntityRepository'
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01