假设您使用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)
));