CI に教義を統合するためのリンクを検索し、この質問などの回答は、(CI 2)古くなっています。 これは私が作ったと私がチェックCI 3のための新しいチュートリアルでは、働いている:
$autoload[‘libraries’] = array(‘doctrine’);
今すぐあなたの教義CodeIgniterのライブラリ
を作成するには、ここにあなたのDoctrine.phpファイルがどのように見えるかです。あなたのニーズに合わせてカスタマイズしてください。
<?php
/**
* Doctrine 2.4 bootstrap
*
*/
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSQLLogger;
class Doctrine {
public $em = null;
public function __construct()
{
// load database configuration from CodeIgniter
require_once APPPATH.'config/database.php';
// include Doctrine's ClassLoader class
require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';
// load the Doctrine classes
$doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'third_party');
$doctrineClassLoader->register();
// load the entities
$entityClassLoader = new ClassLoader('Entities', APPPATH.'models');
$entityClassLoader->register();
// load the proxy entities
$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
$proxiesClassLoader->register();
// load Symfony2 classes
// this is necessary for YAML mapping files and for Command Line Interface (cli-doctrine.php)
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
// Set up the configuration
$config = new Configuration;
// Set up caches
if(ENVIRONMENT == 'development') // set environment in index.php
// set up simple array caching for development mode
$cache = new \Doctrine\Common\Cache\ArrayCache;
else
// set up caching with APC for production mode
$cache = new \Doctrine\Common\Cache\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// set up annotation driver
$driver = new \Doctrine\ORM\Mapping\Driver\PHPDriver(APPPATH.'models/Mappings');
$config->setMetadataDriverImpl($driver);
// Proxy configuration
$config->setProxyDir(APPPATH.'/models/Proxies');
$config->setProxyNamespace('Proxies');
// Set up logger
$logger = new EchoSQLLogger;
$config->setSQLLogger($logger);
$config->setAutoGenerateProxyClasses(TRUE); // only for development
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database']
);
// Create EntityManager, and store it for use in our CodeIgniter controllers
$this->em = EntityManager::create($connectionOptions, $config);
}
}
開発中に非常に有用であるコマンドラインツールの数と
Doctrineの船は、コマンドラインツールを設定します。これらの行は、コマンドラインツールを使用するためのsymfonyのクラスをロードするために、Doctrine.phpファイルに存在する(とYAMLマッピングファイルのための)場合
チェック:
$symfonyClassLoader = new ClassLoader('Symfony', APPPATH.'third_party/Doctrine');
$symfonyClassLoader->register();
あなたはのEntityManagerにアプリケーションを登録する必要があります
<?php
/**
* Doctrine CLI bootstrap for CodeIgniter
*
*/
define('APPPATH', dirname(__FILE__) . '/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');
require APPPATH.'libraries/Doctrine.php';
$doctrine = new Doctrine;
$em = $doctrine->em;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
?>
今すぐPHPのコマンドラインからこのスクリプトを実行し、コマンドの一覧が表示されます。以下の内容でアプリケーションディレクトリでCLI-doctrine.phpファイルを作成することで、タスクを利用するコンソールツールご利用いただけます。
php cli-doctrine.php
データベースからマッピングクラスを生成します。
php cli-doctrine.php orm:convert-mapping --from-database annotation models/Entities
あなたはこのエラーが出る場合: 致命的なエラー:)(未定義の機能教義\共通\キャッシュ\のapc_fetchに呼び出し APCの拡張機能をインストールPHPの場合:
sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart
生産モードあなたは、APCのような本当のキャッシュシステムを使用したいと思うEchoSqlLogger
を取り除く、とDoctrine.php
申し訳 gitのクローンは、私は私の最初の答えでミスを犯しました。私はmasterブランチのcomposer.jsonを見ましたが、それが2.1-stableブランチに入っているかどうかを確認しませんでした。私は今それを修正しました。 –
私はまだComposerとどうすればよいか分かりません。教義のダウンロードにはjsonファイルがありますが、それだけです。 – Lance