尝试运行doctrine命令时“em未定义错误”

时间:2012-12-12 13:58:23

标签: zend-framework configuration doctrine-orm command-line-interface

我刚刚设置了一个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

现在,如果我将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 \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)
));

1 个答案:

答案 0 :(得分:6)

尝试:

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