条令2.3.4找不到存储库(class_parents():类不存在,无法加载)


doctrine 2.3.4 cannot find repository (class_parents(): Class does not exist and could not be loaded)

这是我的文件夹结构。

php-orm
    doctrine
        Amphur.php
    vendor
        bin
        composer
        doctrine
        symfony
        autoload.php
    list.php

这是list.php文件。

<?php
include 'config.php';
use Doctrine'ORM'Tools'Setup;
use Doctrine'ORM'EntityManager;
require_once 'vendor/autoload.php';
$paths = array(__DIR__ . '/doctrine');
$isDevMode = true;
$dbParams = array(
    'driver' => 'pdo_mysql',
    'user' => $db[$dbuse]['username'],
    'password' => $db[$dbuse]['password'],
    'dbname' => $db[$dbuse]['database'],
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
$class_repo = $entityManager->getRepository('Amphur');
//$provinces = $class_repo->findBy('', array('PROVINCE_NAME' => 'ASC'), 50, 0);
$provinces = $class_repo->findAll();
print_r($provinces);

这是条令/Amphur.php文件。

<?php
// doctrine/Amphur.php
/**
 * @Entity @Table(name="amphur")
 **/
class Amphur
{

    /** @AMPHUR_ID @Column(type="integer") @GeneratedValue **/
    protected $id;
    /** @Column(type="string") **/
    protected $amphur_name;

}

数据库:test_db表:amphur[amphur_ID|amphur_CODE|amphur_NAME|GEO_ID|PROVINCE_ID]

运行时,出现错误警告:class_parents():class Amphur不存在,无法加载

如果我已经有了现有的数据库,如何获取存储库?

包含Amphur文件以清除未找到的类。稍后您可以了解如何配置自动加载器以在条令目录中查找文件。

require_once 'vendor/autoload.php';
require_once 'doctrine/Amphur.php';

还需要向Amphur 添加Id注释

/** @AMPHUR_ID 
 * @Id
 * @Column(type="integer") 
 * @GeneratedValue 
 * **/
protected $id;

这是一个调试提示。把你的错误信息复制/粘贴到谷歌搜索栏中。你可能会惊讶于有这么多解决方案。