我已阅读this tutorial,我试图在Zend2项目中设置Doctrine2:
我已经按照教程在两个模块中的配置中注册了doctrine实体路径,我想拥有实体。
namespace MyNamespace;
return array(
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Doctrine/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
),
'view_manager' => array(
'template_path_stack' => array(
'PBT' => __DIR__ . '/../view'
),
),
);
我宣布了一个非常简单的实体:
namespace MyNamespace\Doctrine\Entity;
use Doctrine\ORM\Mapping as ORM;
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id");
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $_id;
/**
* @ORM\Column(type="string", name="email")
*/
protected $_email;
/**
* @ORM\Column(type="string", name="passwordHash")
*/
protected $_passwordHash;
}
我运行了一些doctrine命令,希望他们在我的数据库中创建表:
./vendor/bin/doctrine-module migrations:generate
这里出现了错误:
PHP Fatal error: Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Given route does not implement Console route interface' in PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php:81
Stack trace:
#0 PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php(51): Zend\Mvc\Router\Console\SimpleRouteStack->routeFromArray(Array)
#1 PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/SimpleRouteStack.php(140): Zend\Mvc\Router\Console\SimpleRouteStack->addRoute('home', Array)
#2 PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/SimpleRouteStack.php(84): Zend\Mvc\Router\SimpleRouteStack->addRoutes(Array)
#3 [internal function]: Zend\Mvc\Router\SimpleRouteStack::factory(Array)
#4 truncated mention to 'PROJECT_DIR' in PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 860
Fatal error: Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Given route does not implement Console route interface' in PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 860
Zend\Mvc\Router\Exception\RuntimeException: Given route does not implement Console route interface in PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php on line 81
Call Stack:
0.0001 633648 1. {main}() PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module:0
0.0458 650288 2. include('PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module.php') PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module:4
0.1666 878808 3. Zend\Mvc\Application::init() PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module.php:46
1.6689 5914064 4. Zend\Mvc\Application->bootstrap() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:254
1.6999 6515856 5. Zend\ServiceManager\ServiceManager->get() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:153
1.6999 6516648 6. Zend\ServiceManager\ServiceManager->create() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:481
1.6999 6516648 7. Zend\ServiceManager\ServiceManager->doCreate() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:557
1.6999 6516728 8. Zend\ServiceManager\ServiceManager->createFromFactory() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:598
1.7011 6537712 9. Zend\ServiceManager\ServiceManager->createServiceViaCallback() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:983
1.7011 6538200 10. call_user_func() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:853
1.7011 6538272 11. Zend\Mvc\Service\RouterFactory->createService() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:853
1.7013 6540728 12. call_user_func() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Service/RouterFactory.php:65
1.7058 6689416 13. Zend\Mvc\Router\SimpleRouteStack::factory() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Service/RouterFactory.php:65
1.7071 6742992 14. Zend\Mvc\Router\SimpleRouteStack->addRoutes() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/SimpleRouteStack.php:84
1.7071 6743848 15. Zend\Mvc\Router\Console\SimpleRouteStack->addRoute() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/SimpleRouteStack.php:140
1.7071 6743928 16. Zend\Mvc\Router\Console\SimpleRouteStack->routeFromArray() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php:51
Zend\ServiceManager\Exception\ServiceNotCreatedException: An exception was raised while creating "Router"; no instance returned in PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 860
Call Stack:
0.0001 633648 1. {main}() PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module:0
0.0458 650288 2. include('PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module.php') PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module:4
0.1666 878808 3. Zend\Mvc\Application::init() PROJECT_DIR/vendor/doctrine/doctrine-module/bin/doctrine-module.php:46
1.6689 5914064 4. Zend\Mvc\Application->bootstrap() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:254
1.6999 6515856 5. Zend\ServiceManager\ServiceManager->get() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:153
1.6999 6516648 6. Zend\ServiceManager\ServiceManager->create() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:481
1.6999 6516648 7. Zend\ServiceManager\ServiceManager->doCreate() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:557
1.6999 6516728 8. Zend\ServiceManager\ServiceManager->createFromFactory() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:598
1.7011 6537712 9. Zend\ServiceManager\ServiceManager->createServiceViaCallback() PROJECT_DIR/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:983
欢迎所有精彩或不精彩的想法......如果您在我的问题中看到如何修复代码显示,请...随意!
编辑:添加了完整的错误转储。请注意,通过Web的所有内容都在运行,只是命令行崩溃。
答案 0 :(得分:4)
这适用于Zend Framework 2.2.1。您可以临时使用2.2.0或更低版本。
答案 1 :(得分:1)
您的配置至少有两个错误:
首先,在错误消息状态下,有一个名为Router
的服务正在从表格工厂中被请求。这与您的项目配置有关,不太可能与Doctrine有任何关系。
您的实体未通过班级注释标记为实体。
要修复#2,你需要:
namespace MyNamespace\Doctrine\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User
{
/// ...