1

以前从未接触过 Doctrine(1 或 2),我正在关注Doctrine 2 的本教程

我正处于使用命令行生成数据库模式的地步。这是 cli-config.php 文件,根据教程:

<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);

但是,当我运行它时,我得到一个错误:

Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php' 

因为 cli-config.php 文件引用的那个类不存在。我也尝试过清空 cli-config.php 文件,这当然也不起作用 - 说“未定义帮助程序“em”。”

我使用的是 2.0.0BETA3 版本。我知道这是一个测试版,所以他们可能已经改变了一些文件,但我在任何地方都找不到那个类。

关于如何让它工作的任何想法?

4

2 回答 2

2

XML Getting Started 中的文档在这方面已经过时。请参阅手册中的工具部分,了解如何配置 CLI 工具:

http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html

其余所有仍然按描述工作。我会尽快更新这部分。

于 2010-08-25T11:55:25.110 回答
2

假设您使用pear安装了 Doctrine

$ sudo pear install pear.doctrine-project.org/doctrineORM

这将安装三个“Doctrine 2”包:DoctrineCommon、DoctrineDBAL 和 DoctrineORM。在 Ubuntu 上,这些软件包将位于 /usr/share/php/Doctrine 中,而学说命令行实用程序将安装在 /usr/bin 中。

通过此设置,这是您可以使用的 cli-config.php 版本(注意:DIR前后应该有两个下划线。由于某种原因,它们没有显示)。

<?php
require ‘Doctrine/ORM/Tools/Setup.php’;
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();

require_once 'Doctrine/Common/ClassLoader.php';

$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_mysql',
        'dbname' => 'bugs',
        'user' => 'bugs',
        'password' => 'xyzabc',
  'host' => 'localhost' );

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

$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)
));
于 2010-10-28T04:07:14.200 回答