doctrine orm:schema-tool:create - Class Bug不存在

时间:2012-02-22 00:25:54

标签: doctrine doctrine-orm

嗨,这是我第一次做doctrin22,但我无法让它工作,

这是我的代码

的index.php

<?php
if (getenv('APPLICATION_ENV')) {
    define('APPLICATION_ENV', getenv('APPLICATION_ENV'));
} else {
    define('APPLICATION_ENV', 'production');
}

require_once 'Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader->register();

$config = new Doctrine\ORM\Configuration(); // (2)

// Proxy Configuration (3)
$config->setProxyDir(__DIR__.'/lib/MyProject/Proxies');
$config->setProxyNamespace('MyProject\Proxies');
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == "development"));

// Mapping Configuration (4)
$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/config/mappings/xml");
$config->setMetadataDriverImpl($driverImpl);


// Caching Configuration (5)
if (APPLICATION_ENV == "development") {
    $cache = new \Doctrine\Common\Cache\ArrayCache();
} else {
    $cache = new \Doctrine\Common\Cache\ApcCache();
}
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);

// database configuration parameters (6)
$conn = array(
    'driver' => 'pdo_sqlite',
    'path' => __DIR__ . '/db.sqlite',
);

// obtaining the entity manager (7)
$evm = new Doctrine\Common\EventManager();
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
?>

CLI-config.php中

<?php
require_once 'index.php';
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)
));
?>

和我的文件夹结构

myproject/index.php
myproject/cli-config.php
myproject/config/mappings/xml/Bug.dcm.xml
myproject/config/mappings/xml/Product.dcm.xml
myproject/config/mappings/xml/User.dcm.xml

我跑的时候     myproject / doctrine orm:schema-tool:create --dump-sql

我得到以下

doctrine orm:schema-tool:create --dump-sql
PHP Warning:  class_parents(): Class Bug does not exist and could not be loaded in /usr/local/zend/share/pear/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php on line 40
PHP Stack trace:
PHP   1. {main}() /usr/local/zend/bin/doctrine:0
PHP   2. include() /usr/local/zend/bin/doctrine:4
PHP   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
PHP   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
PHP   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
PHP   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
PHP   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
PHP   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
PHP   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
PHP  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
PHP  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254
PHP  12. Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:231
PHP  13. class_parents() /usr/local/zend/share/pear/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:40

Warning: class_parents(): Class Bug does not exist and could not be loaded in /usr/local/zend/share/pear/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php on line 40

Call Stack:
    0.0001     625400   1. {main}() /usr/local/zend/bin/doctrine:0
    0.0002     639440   2. include('/usr/local/zend/bin/doctrine.php') /usr/local/zend/bin/doctrine:4
    0.0086    4245576   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
    0.0151    6311808   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
    0.0164    6761376   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
    0.0169    6761544   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
    0.0171    6761920   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
    0.0171    6761920   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
    0.0172    6764016   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
    0.0172    6764064  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
    0.0172    6764280  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254
    0.0173    6799712  12. Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:231
    0.0173    6799760  13. class_parents() /usr/local/zend/share/pear/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:40

PHP Warning:  array_reverse() expects parameter 1 to be array, boolean given in /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 231
PHP Stack trace:
PHP   1. {main}() /usr/local/zend/bin/doctrine:0
PHP   2. include() /usr/local/zend/bin/doctrine:4
PHP   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
PHP   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
PHP   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
PHP   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
PHP   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
PHP   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
PHP   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
PHP  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
PHP  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254
PHP  12. array_reverse() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:231

Warning: array_reverse() expects parameter 1 to be array, boolean given in /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 231

Call Stack:
    0.0001     625400   1. {main}() /usr/local/zend/bin/doctrine:0
    0.0002     639440   2. include('/usr/local/zend/bin/doctrine.php') /usr/local/zend/bin/doctrine:4
    0.0086    4245576   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
    0.0151    6311808   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
    0.0164    6761376   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
    0.0169    6761544   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
    0.0171    6761920   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
    0.0171    6761920   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
    0.0172    6764016   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
    0.0172    6764064  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
    0.0172    6764280  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254
    0.0176    6799840  12. array_reverse() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:231

PHP Warning:  Invalid argument supplied for foreach() in /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 231
PHP Stack trace:
PHP   1. {main}() /usr/local/zend/bin/doctrine:0
PHP   2. include() /usr/local/zend/bin/doctrine:4
PHP   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
PHP   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
PHP   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
PHP   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
PHP   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
PHP   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
PHP   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
PHP  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
PHP  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254

Warning: Invalid argument supplied for foreach() in /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 231

Call Stack:
    0.0001     625400   1. {main}() /usr/local/zend/bin/doctrine:0
    0.0002     639440   2. include('/usr/local/zend/bin/doctrine.php') /usr/local/zend/bin/doctrine:4
    0.0086    4245576   3. Doctrine\ORM\Tools\Console\ConsoleRunner::run() /usr/local/zend/bin/doctrine.php:50
    0.0151    6311808   4. Symfony\Component\Console\Application->run() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/ConsoleRunner.php:39
    0.0164    6761376   5. Symfony\Component\Console\Application->doRun() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:118
    0.0169    6761544   6. Symfony\Component\Console\Command\Command->run() /usr/local/zend/share/pear/Symfony/Component/Console/Application.php:194
    0.0171    6761920   7. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /usr/local/zend/share/pear/Symfony/Component/Console/Command/Command.php:224
    0.0171    6761920   8. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
    0.0172    6764016   9. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:131
    0.0172    6764064  10. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:178
    0.0172    6764280  11. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() /usr/local/zend/share/pear/Doctrine/ORM/Mapping/ClassMetadataFactory.php:254




[ReflectionException]     
Class Bug does not exist  



orm:schema-tool:create [--dump-sql]

1 个答案:

答案 0 :(得分:0)

由于您没有发布Bug.dcm.xml文件,我无法看到您是否正确宣布了您的课程。但是查看您的xml文件名,您忘记为Bug类添加命名空间。如果你给你的Bug类命名空间Foo你的文件名应该是Foo.Bug.dcm.xml。

您需要做的另一件事是将选择的命名空间添加到您的doctrine类加载器中。就像你使用Doctrine命名空间一样。我的情况下,你使用名称空间Foo,它将如下所示:

$classLoader = new \Doctrine\Common\ClassLoader('Foo', <<PATH_TO_FOO>>);
$classLoader->register();

替换&lt;&gt;到命名空间开始的路径。

如果这不能解决您的问题,请发布Bug.dcm.xml。