如何使用注释使用doctrine 2在我的项目中调整模块ZfcUser/zfcuserDoctrineORM?

ton*_*s85 6 doctrine annotations zfcuser

我是在阿根廷写的,原谅我的英语很少.我有一些问题与模块ZfcUserzfcuserDoctrineORM.我需要将它们集成到我的项目中.我正在使用Zend framework 2,doctrine 2.3和postgreSQL,这是我第一次使用这些工具.出于这个原因,有很多事情我不能很好地支配,我有我所有的模块/config/application.config.php,我的连接是在我的数据库中配置的/config/autoload/local.php

Local.php


    return array(
      'doctrine' => array(
        'connection' => array(
            'orm_default' =>array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
                    'params' => array(
                        'host'     => 'localhost',
                        'port'     => '5432',
                        'user'     => 'postgres',
                        'password' => 'postgres',
                        'dbname'   => 'ministerio',
                    )
                )
            )
        ),
    );

application.config.php


    return array(
      'modules' => array(
        'Application',
        'DoctrineModule',
        'DoctrineORMModule',
        'Reeser',           // Name of my module
        'ZfcBase',
        'ZfcUser', 
        'ZfcUserDoctrineORM',  

    ),
    'module_listener_options' =>array(
          'config_glob_paths'    =>array(
              'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' =>array(
             './module',
             './vendor',
          ),
       ),
    );

为了映射我的数据库,我使用了带有学说的注释,我在我的模块中生成了自己的实体用户.

我添加了配置存档zfcuser.global.phpzfcuserdoctrineorm.global.php我的自动加载目录,但我不知道如何配置它们以便存档识别我的实体.

进入zfcuser.global.php

    'zend_db_adapter' => 'Zend\Db\Adapter\Adapter',    // should this comment it?

    'user_entity_class' => 'Reeser\Entity\User',

    'login_redirect_route' => 'Reeser/index/index.phtml',

    return array(
         'zfcuser' => $settings,        // How I configure this code?
         'service_manager' =>array(     
         'aliases' => array(
         'zfcuser_zend_db_adapter' => (isset($settings['zend_db_adapter'])) ?
         $settings['zend_db_adapter']: 'Zend\Db\Adapter\Adapter',
            ),
         ),
    );  

进入zfcuserdoctrineorm.global.php

    return array(
       'doctrine' => array(
          'driver' => array(
             'zfcuser_driver' =>array(
                 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                 'cache' => 'array',
                 'paths' => array(__DIR__ .'/../src/Reeser/Entity')
            ),

            'orm_default' =>array(
                'drivers' => array(
                    'ZfcUser\Entity'  =>  'zfcuser_driver'
                )
            )
         )
      ),
    );

我看到该模块zfcuserDoctrineORM适用于XML.模块是否可以适用于注释?如果可以,我如何调整我的实体用户到这个模块?我应该修改哪些档案?

Ocr*_*ius 6

您不需要调整ZfcUserDoctrineORM来使用注释映射.DoctrineORMModule本身支持混合映射(您可以选择决定使用哪些驱动程序映射哪些实体).关于ZfcUser的配置,我个人根本没有修改它(我只对ZfcUserDoctrineORM做了什么做了一些覆盖).

  1. 删除config/autoload/zfcuser.global.php(你不需要它)
  2. 去掉 config/autoload/zfcuserdoctrineorm.global.php
  3. 在定义用户实体的模块中,如果要覆盖ZfcUserDoctrineOrm的注释驱动程序(假设文件在YourModule/config/module.config.php),请使用以下命令:

    // entity mappings
    'doctrine' => array(
        'driver' => array(
            'zfcuser_entity' => array(
                // customize path
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'paths' => array(__DIR__ . '/../src/YourModule/Entity'),
            ),
            'orm_default' => array(
                'drivers' => array(
                    'YourModule\Entity' => 'zfcuser_entity',
                ),
            ),
        ),
    ),
    
    // ZfcUser specific config
    'zfcuser' => array(
        'user_entity_class'       => 'YourModule\Entity\User',
        'enable_default_entities' => false,
    ),
    
    Run Code Online (Sandbox Code Playgroud)

这适用于0.1.x版本的ZfcUserDoctrineORM