问题
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