0

私は Doctrine を扱う初心者です。私は彼らのウェブサイトに行き、最新のものと思われるバージョン 2.0 (安定版) を見つけました。いくつかの問題がありましたが、PEAR メソッドを使用してインストールしました。ドキュメンテーションは私にはかなり面倒に思えましたが、インターネットで検索したところ、boostrap ファイルのサンプルが見つかりました。Doctrine 2.0 のドキュメントはここにあります 。

`指示に従い、require_once ('libs/Doctrine/Common/ClassLoader.php') と同様にクラス ロード ファイルをインクルードしました。最初に。

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'libs');
$classLoader->register();

$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'libs');
$classLoader->register();

$classLoader = new \Doctrine\Common\ClassLoader('Entities', 'libs');
$classLoader->register();

$classLoader = new \Doctrine\Common\ClassLoader('Dao', 'libs');
$classLoader->register();

$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$config->setProxyDir('/Proxies');
$config->setProxyNamespace('Proxies');

$driverImpl = $config->newDefaultAnnotationDriver(array("/Entities"));
$config->setMetadataDriverImpl($driverImpl);

$connectionOptions = array(
'dbname' => 'db',
'user' => 'root',
'password' => 'mypassword',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',);

$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

// At this point no actual connection to the database is created
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionOptions);//('mysql:  //root:127.0.0.1@127.0.0.1/db');
// The first time the connection is needed, it is instantiated
// This query triggers the connection to be created
$conn->exec('SHOW TABLES');`

メソッド「execute」はバージョン 2 では「exec」であり、バージョン 2 では他の代わりに DriverManager を使用していることがわかりました。今、Doctrine が機能するかどうかをテストしようとすると、出力が得られず、予期しない T_STRING のエラーが発生します。これは、実際にはコマンドが理解されていないことを意味します。

バージョン 1.2 では getPath() を使用したテストがありますが、この関数はバージョン 2.0 には存在しないか、何か間違っている可能性があります。$conn->exec も何もしないことに注意してください。

Windows 7 と WAMP サーバー バージョン 2、PHP 5.3.3 を実行しています。プロジェクト ディレクトリにある Doctrine のフォルダを取り出しました。プロジェクト ディレクトリに追加せずに Doctrine を使用する機会はありますか?

前もって感謝します。

4

2 に答える 2

0

なぜ接続をトリガーする必要があるのですか? 初めて使用するときは、遅延接続します。EntityManager::create メソッドの後は、うまくいくはずです。

于 2010-12-28T12:15:40.090 に答える
0

問題をどのように説明したかはわかりませんが、Zend Studio に組み込まれているようなデバッガーを使用することをお勧めします (または、Aptana などの Eclipse ベースの IDE で Zend をセットアップできます)。これにより、物事がより明確になります。

于 2011-07-07T20:00:16.977 に答える