我刚刚设置了一个 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
正在运行该原则.php从文件夹
/Library/WebServer/Documents/zf2-Skel-NewProj1/vendor/bin
现在,如果我将 CLI 用于我的一个 ZF1.11 项目,它可以正常工作。
要使其正常工作,我必须编辑位于 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 DoctrineCommonClassLoader('DoctrineORM', realpath(__DIR__ . '/../../lib'));
$classLoader->register();
$classLoader = new DoctrineCommonClassLoader('DoctrineDBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
$classLoader->register();
$classLoader = new DoctrineCommonClassLoader('DoctrineCommon', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
$classLoader->register();
$classLoader = new DoctrineCommonClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
$classLoader->register();
$classLoader = new DoctrineCommonClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new DoctrineCommonClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new DoctrineORMConfiguration();
$config->setMetadataCacheImpl(new DoctrineCommonCacheArrayCache);
$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 = DoctrineORMEntityManager::create($connectionOptions, $config);
$helpers = new SymfonyComponentConsoleHelperHelperSet(array(
'db' => new DoctrineDBALToolsConsoleHelperConnectionHelper($em->getConnection()),
'em' => new DoctrineORMToolsConsoleHelperEntityManagerHelper($em)
));
尝试:
vendor\bin\doctrine-module orm:schema-tool:update --dump-sql