0

我已阅读本教程,并尝试在 Zend2 项目中设置 Doctrine2:

  1. 我已将 Doctrine2 注册为依赖项并成功安装
  2. 我已按照教程在我希望拥有实体的两个模块的配置中注册理论实体路径。

    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'
            ),
        ),
    );
    
  3. 我已经声明了一个非常简单的实体:

    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;
    }
    
  4. 我运行了一些学说命令,希望他们能在我的数据库中创建表:

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

欢迎所有优秀或不优秀的想法......如果您看到如何修复我的问题中的代码显示,请......随意!

编辑:添加了完整的错误转储。请注意,通过网络的一切都在工作,只是命令行正在崩溃。

4

2 回答 2

4

这适用于 Zend Framework 2.2.1。您可以暂时使用 2.2.0 或更低版本。

于 2013-06-14T08:06:51.077 回答
1

您的配置至少有两个错误:

  1. 首先,在错误消息状态下,有一个服务被称为Router从看起来像表单工厂的地方请求。这与您的项目配置有关,不太可能与 Doctrine 有任何关系。

  2. 您的实体未通过类级别注释标记为实体。

要修复#2,您需要:

namespace MyNamespace\Doctrine\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class User
{
    /// ...
于 2013-06-14T03:01:44.963 回答