Doctrine 和 Codeigniter:找不到实体

Doctrine and Codeigniter: Entity not found

我正在使用由库 class 加载的 Codeigniter 3 和 Doctrine 2。 Doctrine 本身是通过 composer autoload 加载的。

在本地主机上(windows 和 php 5.6.0)我正在使用 php 内置服务器,一切正常。 当我将项目上传到我的网络服务器时(Plesk with nginx and proxied apache, php 5.6.15),我收到以下错误:

An uncaught Exception was encountered

Type: Doctrine\Common\Persistence\Mapping\MappingException

Message: Class 'Entity\User' does not exist

Filename: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php    
Line Number: 96

Backtrace:

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php
Line: 41
Function: nonExistingClass

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
Line: 282
Function: getParentClasses

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
Line: 313
Function: getParentClasses

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Line: 78
Function: loadMetadata

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
Line: 216
Function: loadMetadata

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
Line: 281
Function: getMetadataFor

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
Line: 44
Function: getClassMetadata

File: /var/www/vhosts/example.org/project.example.org/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
Line: 698
Function: getRepository

File: /var/www/vhosts/example.org/project.example.org/application/controllers/User.php
Line: 18
Function: getRepository

File: /var/www/vhosts/example.org/project.example.org/index.php
Line: 301
Function: require_once

控制器如下:

....
public function show($id)
{
    $user = $this->doctrine->em->getRepository('Entity\User')->findOneBy(array('id' => $id));
}
....

和学说图书馆: 使用 Doctrine\Common\ClassLoader, Doctrine\ORM\Tools\Setup, Doctrine\ORM\EntityManager;

class Doctrine {

    public $em;
    public function __construct()
    {
        // Load the database configuration from CodeIgniter
        require APPPATH . 'config/database.php';

        $connection_options = array(
            'driver'        => 'pdo_mysql',
            'user'          => $db['default']['username'],
            'password'      => $db['default']['password'],
            'host'          => $db['default']['hostname'],
            'dbname'        => $db['default']['database'],
            'charset'       => $db['default']['char_set'],
            'driverOptions' => array(
                'charset'   => $db['default']['char_set'],
            ),
        );
        // With this configuration, your model files need to be in     application/models/Entity
        // e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
        $models_namespace = 'Entity';
        $models_path = APPPATH . 'models';
        $proxies_dir = APPPATH . 'models/proxies';
        $metadata_paths = array(APPPATH . 'models/entity');
        // Set $dev_mode to TRUE to disable caching while you develop
        $dev_mode = true;
        // If you want to use a different metadata driver, change createAnnotationMetadataConfiguration
        // to createXMLMetadataConfiguration or createYAMLMetadataConfiguration.
        $config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode, $proxies_dir);
        $this->em = EntityManager::create($connection_options, $config);
        $loader = new ClassLoader($models_namespace, $models_path);
        $loader->register();
    }

}

库是通过 autoload.php:

加载的
$autoload['libraries'] = array('OAuth2', 'session', 'doctrine');

实体位于 models\Entity\

<?php
namespace Entity;
use Doctrine\ORM\Mapping\Entity;

defined('BASEPATH') OR exit('No direct script access allowed');


/**
 * User Model
 *
 * @Entity
 * @Table(name="user")
 */
class User {

    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
     protected $id;
....

奇怪的是它在本地工作。 有什么想法吗?

发现问题:linux 的区分大小写:

实体的文件夹要根据命名空间大小写。由于目录是 models\entity\ 并且 Windows' 文件系统不区分大小写,因此它在本地工作。但是 linux 是区分大小写的,需要 models\Entity。 将文件夹重命名为 models\Entity,它正在运行。