Lan*_*nce 6 codeigniter doctrine-orm
我已成功安装最新版本的CodeIgniter并具有基本的MVC模式.我注意到的问题是CI在查询时自然不允许准备好的语句.所以,我决定从GitHub下载Doctrine 1 .我对Doctrine很新,需要一些帮助将它与CI集成,所以我遵循了本教程.
在我的一个控制器中,我有
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
Run Code Online (Sandbox Code Playgroud)
但是,当我在浏览器中加载视图时,我会遇到错误的阅读
消息:require_once(/Applications/MAMP/htdocs/CodeIgniter/application/libraries/Doctrine/Common/ClassLoader.php):无法打开流:没有这样的文件或目录
在从GitHub进一步检查Doctrine下载后,在那里似乎没有任何标题为"common"的文件夹.我对CI很新,尤其是学说.有没有人有一些建议可以帮我搞定这个?此外,是否可以使用MySQLi驱动程序而不是使用Doctrine的PDO驱动程序?
Ada*_*ney 12
直接从GitHub下载Doctrine ORM不包括其他依赖项.这些由Composer管理.如果查看composer.json文件,可以看到这些依赖项.如果要手动安装它们,它们是:
我相信这就是全部.您必须将这些文件合并到适当的目录中,因为它们遵循PSR-0标准进行类的自动加载.
或者,使用Composer安装带有以下composer.json文件的Doctrine 2,并自动安装任何其他依赖项.然后与CodeIgniter集成.
{
"minimum-stability": "stable",
"require": {
"doctrine/orm": "2.3.*"
}
}
Run Code Online (Sandbox Code Playgroud)
index.php在需要CodeIgniter核心之前,通过添加一行来包含自动加载器文件来编辑CodeIgniter应用程序的文件.
require_once BASEPATH.'../vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
Run Code Online (Sandbox Code Playgroud)
此外,如果使用Composer进行安装,请使用此编辑版本的bootstrap作为内容application/libraries/Doctrine.php,这对我有用
<?php
use 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');
// Set $dev_mode to TRUE to disable caching while you develop
$config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir);
$this->em = EntityManager::create($connection_options, $config);
$loader = new ClassLoader($models_namespace, $models_path);
$loader->register();
}
}
Run Code Online (Sandbox Code Playgroud)
注意:CodeIgniter的第3版在发布时,可以使用Composer进行安装,但不能使用版本2进行安装.