creating mapped ORM Entities without the cli?

可紊 提交于 2020-01-17 03:59:09

问题


I'm working on an apiglity project that uses zend framework 2 and the doctrine.

i included in local.config.php of my zf2 project the following code:

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>',
            )
        )
    )
),
);

in my main module's configuration file (module.config.php) I included the following code:

 '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'
            )
        )
    )
)

I read the following URL: http://samsonasik.wordpress.com/2013/04/10/zend-framework-2-generate-doctrine-entities-from-existing-database-using-doctrinemodule-and-doctrineormmodule/

and it says that to create Entities from my Database I need to use vendor/bin/doctrine-module.

When I try to execute doctrine-module I get the following error:

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

by reading the following stack overflow question: Apigility - How to use Doctrine ORM Module from ZF2 command line

I understood that the doctrine-module client is not necessary and I should execute

php public/index.php orm:info

in order to see the status of doctrine.

when executing this I get the following error message:

[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.                                            

this is because I created the Entities folder and it's empty.

now the question is, how do I create Entities based on database if I can't use the doctrine-module ?


回答1:


'paths' => array(DIR . '/../src/' . NAMESPACE . '/Entity')

I don't understand this path.. Can you try to a simple path? For example

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

And write your entity into the YouModule module, in src/YouModule/Entity



来源:https://stackoverflow.com/questions/26903425/creating-mapped-orm-entities-without-the-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!