开发者

Autoload issue in using Doctrine2

cli-config.php

<?php

require_once 'Doctrine/Common/ClassLoader.php';

$path = dirname(dirname(dirname(__FILE__)));

$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);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$driver = new \Doctrine\ORM\Mapping\Driver\YamlDriver($path . '/doctrine2/default/yml');
$config->setMetadataDriverImpl($driver);

require_once $path . '/database.php';
$db = new DATABASE_CONFIG;

$connectionOptions = array(
    'driver' => 'pdo_pgsql',
    'host' => $db->default['host'],
    'user' => $db->default['login'],
    'password' => $db->default['password'],
    'dbname' => $db->default['database'],
);

$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()),
            'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(),
            'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
        ));

With these settings, I could successfully generate yml and entities with following commands:

doctrine2 orm:convert-mapping --from-database yml yml

doctrine2 orm:generate-entities Entities/

When executing command "doctrine2 orm:validate-schema", it showed following errors:

[ReflectionException]

Class XXX does not exist

But I could find the XXX.php in Entities folder. I've tried to add namespace Entiti开发者_JAVA技巧es, but it still couldn't find the model. Maybe I missed something?


well, I found the answer. Just change the commands to

doctrine2 orm:convert-mapping --namespace="Entities\" --from-database yml yml

doctrine2 orm:generate-entities .

doctrine2 orm:validate-schema

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜