我正在将Doctrine用于我正在开发的PHP项目中。
文件夹结构如下所示:
app
-actions
-controllers
-doctrine
-entities
ConnectionFactory.class.php
css
img
js
views
好的,我正在尝试在Doctrine
课程中引用ConnectionFactory
。
<?php
use Doctrine\ORM\Tools\Setup;
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR);
require_once "Doctrine/ORM/Tools/Setup.php";
class ConnectionFactory {
private static $instance;
private $entityManager;
private function __construct() { }
public static function getInstance() {
if(!self::$instance) {
self::$instance = new ConnectionFactory();
}
return self::$instance;
}
public function getEntityManager() {
if($this->entityManager == null) {
Setup::registerAutoloadPEAR();
$debug = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . DIRECTORY_SEPARATOR ."/entities"), $debug);
$conn = array(
'driver' => 'pdo_mysql',
'user' => 'root',
//'password' => 'root',
'host' => 'localhost',
'port' => 3306,
'charset' => 'utf8',
'dbname' => 'anuncios'
);
$this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
}
return $this->entityManager;
}
}
?>
嗯,它就像开发环境中的魅力一样。当我把它推到prod时,我收到了一个错误:
require_once(Doctrine/Common/ClassLoader.php): failed to open stream:
No such file or directory in <b>/home/nifes651/public_html/www.mysite.com.br/main/app/Doctrine/ORM/Tools/Setup.php</b> on line <b>74</b><br />
我无法弄清楚为什么这不起作用。开发工作正常。
任何人都可以帮助我吗?感谢!!!