在没有cli的情况下创建映射的ORM实体?

时间:2014-11-13 07:23:58

标签: php zend-framework doctrine-orm zend-framework2 doctrine

我正在开发一个使用zend框架2和学说的apiglity项目。

我在zf2项目的local.config.php中包含以下代码:

return array(
 'doctrine' => array(
    'connection' => array(
        'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
            'params' => array(
                'host'     => 'localhost',
                'port'     => '3306',
                'user'     => '<username>',
                'password' => '<password>',
                'dbname'   => '<db>',
            )
        )
    )
),
);

在我的主模块的配置文件(module.config.php)中,我包含以下代码:

 'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            )
        )
    )
)

我阅读了以下网址: http://samsonasik.wordpress.com/2013/04/10/zend-framework-2-generate-doctrine-entities-from-existing-database-using-doctrinemodule-and-doctrineormmodule/

它表示要从我的数据库创建实体,我需要使用vendor/bin/doctrine-module

当我尝试执行doctrine-module时,我收到以下错误:

PHP Fatal error:  Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for doctrine.cli' in /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:529
Stack trace:
#0 /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/doctrine/doctrine-module/bin/doctrine-module.php(51): Zend\ServiceManager\ServiceManager->get('doctrine.cli')
#1 /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/doctrine/doctrine-module/bin/doctrine-module(4): include('/mnt/storage/ho...')
#2 {main}
thrown in /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 529

Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for doctrine.cli' in /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:529
Stack trace:
#0 /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/doctrine/doctrine-module/bin/doctrine-module.php(51): Zend\ServiceManager\ServiceManager->get('doctrine.cli')
#1 /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/doctrine/doctrine-module/bin/doctrine-module(4): include('/mnt/storage/ho...')
#2 {main}
thrown in /mnt/storage/home/ufk/projects/myalcoholist-apigility/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 529

通过阅读以下堆栈溢出问题: Apigility - How to use Doctrine ORM Module from ZF2 command line

我知道doctrine-module客户端不是必需的,我应该执行

php public/index.php orm:info

以便了解学说的状态。

执行此操作时,我收到以下错误消息:

[Exception]                                                                                                       
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or  
mapping files you should check your mapping configuration for errors.                                            

这是因为我创建了Entities文件夹并且它是空的。

现在的问题是,如果我不能使用doctrine-module,如何根据数据库创建实体?

1 个答案:

答案 0 :(得分:2)

&#39;路径&#39; =&GT;数组( DIR 。&#39; /../ src /&#39;。 NAMESPACE 。&#39; /实体&#39;)

我不明白这条道路。你能尝试一条简单的道路吗? 例如

__DIR__.'/../src/YourModule/Entity'

将您的实体写入Youmodule模块,在src / YouModule / Entity中