2013-06-15 3 views
6

CodeIgniterの最新バージョンを正常にインストールし、基本的なMVCパターンを正常に動作させました。私が気づいた問題は、CIがクエリに関してプリペアドステートメントを自然に許可しないということです。そこで、Doctrine 1をGitHubからダウンロードすることにしました。私はDoctrineを初めて使いこなしており、CIとの統合の助けが必要でしたので、これはtutorialに従っています。私のコントローラの一DoctrineとCodeIgniterの統合

、私は

$this->load->library('doctrine'); 
$this->em = $this->doctrine->em; 

を持っている。しかし、私は私のブラウザでビューをロードするために行くとき、私は、さらに調べると

Message: require_once(/Applications/MAMP/htdocs/CodeIgniter/application/libraries/Doctrine/Common/ClassLoader.php): failed to open stream: No such file or directory

を読んで、エラーで迎えていますGitHubからDoctrineをダウンロードすると、そこにはどこでも共通のタイトルのフォルダはないようです。私はCIと特にDoctrineにはとても新しいです。誰にも私はこれを働かせる助けとなる助言がありますか?また、DoctrineでPDOドライバの代わりにMySQLiドライバを使用することは可能ですか?

答えて

12

GitHubから直接Doctrine ORMをダウンロードしても、他の依存関係は含まれません。これらはComposerによって管理されます。 composer.jsonファイルを見ると、これらの依存関係を見ることができます。あなたがそれらを手動でインストールしたい場合は、以下のとおりです。

  • 教義/共通
  • 教義/インフレクタ
  • 教義/キャッシュ
  • 教義/コレクション
  • 教義/レクサ
  • 教義/注釈
  • ドクトリン/ dbal
  • symfony/console

私はそれがすべてだと信じています。これらのファイルを適切なディレクトリにマージする必要があります。PSR-0 standardsに従うと、クラスの自動読み込みが行われます。

また、次のcomposer.jsonファイルを使用してDoctrine 2をComposerにインストールすると、他の依存関係も自動的にインストールされます。その後、integrate with CodeIgniter

{ 
    "minimum-stability": "stable", 
    "require": { 
     "doctrine/orm": "2.3.*" 
    } 
} 

編集CodeIgniterのコアを必要とする前に、オートローダーファイルを含めるために、単一の行を追加することで、あなたのCodeIgniterアプリのindex.phpファイル。

require_once BASEPATH.'../vendor/autoload.php'; 

require_once BASEPATH.'core/CodeIgniter.php'; 

も作曲してインストールした場合、私のために働いていたものです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(); 
    } 
} 

注:CodeIgniterのバージョン3リリースになりますComposerでインストール可能ですが、バージョン2はインストールできません。

+0

申し訳 gitのクローンは、私は私の最初の答えでミスを犯しました。私はmasterブランチのcomposer.jsonを見ましたが、それが2.1-stableブランチに入っているかどうかを確認しませんでした。私は今それを修正しました。 –

+0

私はまだComposerとどうすればよいか分かりません。教義のダウンロードにはjsonファイルがありますが、それだけです。 – Lance

0

コードイグナイター2 コードイグナイター2はコード構成に少し違いがあります。コードイグナイター2の場合application/librariesフォルダーの代わりにapplication/third_partyフォルダーにDoctrineフォルダーを入れてください(そうでないと機能しません)。

あなたはそれについてhere

0

をより多くを読むことができる私は教義のユーザーガイド http://doctrine-orm.readthedocs.org/en/latest/cookbook/integrating-with-codeigniter.html

からこのチュートリアルに従うことをしようとしたとき、私はそう、私の作曲を経由してインストールしようとすると、この問題が発生した同じ問題を抱えていましたこのウェブサイト http://www.doctrine-project.org/downloads/に行き、手動でDoctrineORM-2.3.3-full.tar.gzのバージョンをダウンロードしてください。エラーはなくなりました。

0

元のポスターの問題は自動読み込みの問題であるようです。私は、ComposerでCodeIgniterとDoctrineを設定しようとしているときに同様の問題が発生しました。 CodeIgniter 3では、コンストラクタのオートローディングを有効にすることができます。これにより、すべてのDoctrineファイルを正しく読み込むことができます。これが機能するには、Composerベンダーのディレクトリにアプリケーション/ベンダーを指定する必要があります。古いバージョンでもそれを行うことができますが、次に、CodeIgniter用のDoctrineライブラリファイルにComposerの自動ロードファイルを手動でインクルードする必要があります。 詳しい情報が必要な場合:私は正確にそれを行う方法を記述したブログ記事を書いた。

+0

あなたのブログ記事の一部をここに追加してください。 – abarisone

2

CI に教義を統合するためのリンクを検索し、この質問などの回答は、(CI 2)古くなっています。 これは私が作ったと私がチェックCI 3のための新しいチュートリアルでは、働いている:

How to install Doctrine 2 in CodeIgniter 3


私はここでそれを繰り返します。

はDoctrineはComposerでインストールすることができ教義

Doctrine 2 ORM’s documentation - Installation and Configuration

をインストールします。 は、あなたのcomposer.jsonファイルで以下の要件を定義します。

{ 
    "require": { 
     "doctrine/orm": "*" 
    } 
} 

その後、あなたのコマンドラインから作曲をインストール呼び出します。ここで

Doctrine 2 ORM’s documentation - Integrating with CodeIgniter

CodeIgniterの

との統合

は手順です。 はDoctrine.phpというフォルダ、システム/アプリケーション/ライブラリにPHPファイルを追加します。これは、D2エンティティマネージャのラッパー/ブートストラップになります。 thirdtpartyフォルダ内にDoctrineフォルダ(Common、DBAL、およびORMを含むフォルダ)を配置します。 必要に応じて、config/autoloadを開きます。PHPファイルと自動ロードDoctrineのライブラリ:

$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

+0

このリンクは質問に答えるかもしれませんが、答えの本質的な部分をここに含めて参考にしてください。リンクされたページが変更された場合、リンクのみの回答は無効になります。 –

+1

アドバイスに従いました –

+0

コピー&ペーストした内容 –

0

autoGenerateProxyClassesをオフにしますが、作曲を経由して、この

を使用することができます。 作曲作成プロジェクトRBZ/CodeIgniterのあなたのプロジェクトのgit経由

https://github.com/dandisy/cihmvctwig.git

関連する問題