0

ZF2 プロジェクトをセットアップし、Doctrine2 用にすべて問題なく構成しました。クエリを実行しようとしているデータベーステーブルが見つからないため、動作し、エラーが発生するだけです。

エンティティも正しく設定されています。すべてhttp://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/に従っています

したがって、CLIを使用してテーブルなどを作成したかったのですが、CLIコマンドを実行すると取得されます

[InvalidArgumentException]       
The helper "em" is not defined.

使用しているコマンド

php doctrine.php orm:schema-tool:update --dump-sql

フォルダからdoctrine.phpを実行しています

/Library/WebServer/Documents/zf2-Skel-NewProj1/vendor/bin

ZF1.11 プロジェクトの 1 つに CLI を使用すると、問題なく動作します。

これを機能させるには、下にある cli-config.php ファイルを編集する必要がありますか?

/Library/WebServer/Documents/zf2-Skel-NewProj1/vendor/doctrine/orm/tools

このファイルの内容は次のとおりです。

<?php

require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();

$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);

$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');

$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);

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

$helpers = 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)
));
4

1 に答える 1

7

試す:

vendor\bin\doctrine-module orm:schema-tool:update --dump-sql

于 2012-12-12T23:44:37.013 に答える