我使用Codeigniter 3和Doctrine 2,它是由庫類加載的。 學說本身通過作曲家自動加載加載。Doctrine和Codeigniter:找不到實體
在本地主機上(窗口與PHP 5.6.0)我使用內置的服務器的PHP和一切工作。 當我上傳項目到我的網絡服務器(的Plesk nginx的和代理了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;
....
奇怪的是,它在本地。 任何想法?