本文介绍了如何使用注释教义2适应模块ZfcUser / zfcuserDoctrineORM在我的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自阿根廷写作,原谅我的英语不大。我有一些问题,模块 ZfcUser zfcuserDoctrineORM 。我需要将它们融入我的项目。我与Zend框架2,学说2.3和PostgreSQL的工作,这是我第一次使用这些工具的工作。出于这个原因,有我不称霸好很多事情,我已经包括了所有的模块在我的 /config/application.config.php 我的连接配置在我的 /config/autoload/local.php

I’m writing from Argentina, forgive my English little. I’m having some problems with modules ZfcUser and zfcuserDoctrineORM. I need to integrate them into my project. I’m working with Zend framework 2 , doctrine 2.3 and postgreSQL and this is the first time I work with these tools. For that reason, there are many things that I don’t dominate well, I have all the modules included in my /config/application.config.php and my connection is configured in my database in /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',
          ),
       ),
    );

为了映射我的数据库我利用教义的注解,我有我自己的实体的用户我的模块中产生的。

In order to map my database I made use of annotations with doctrine and I have my own entity user generated in my module.

我添加的配置档案 zfcuser.global.php zfcuserdoctrineorm.global.php 在我的自动加载的目录,但我不知道如何对它们进行配置,使档案承认我的实体。

I added the configuration archives zfcuser.global.php and zfcuserdoctrineorm.global.php in my autoload directory but I don’t know how to configure them so that the archives recognize my entity.

进入 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的。
可以在模块适应与注释工作?如果这是可能的,我怎么适应我的实体用户在该模块?我应该修改哪些档案?

I saw that module zfcuserDoctrineORM works with XML.Can the module be adapted to work with annotations? If this is possible, how do I adapt my entity user to this module? Which archives should I modify ?

推荐答案

您不需要适应以使用注释映射。 本身支持混合映射(这是你的选择决定哪些实体与驱动程序映射)。关于的配置,我个人根本不修改它(我只是做什么ZfcUserDoctrineORM做一些覆盖)

You don't need to adapt ZfcUserDoctrineORM to use annotation mappings. DoctrineORMModule supports mixed mappings natively (it's your choice to decide which entities to map with which drivers). About ZfcUser's configuration, I personally didn't modify it at all (I only did some overrides on what ZfcUserDoctrineORM does).


  1. 删除配置/自动加载/ zfcuser.global.php (你不需要它)

  2. 删除配置/自动加载/ zfcuserdoctrineorm.global.php

  3. 如果要覆盖ZfcUserDoctrineOrm的注解驱动
  4. 模块定义用户实体,使用后(假设该文件是在 YourModule /配置/ 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,
),


这应为 0.1.x工作 ZfcUserDoctrineORM

这篇关于如何使用注释教义2适应模块ZfcUser / zfcuserDoctrineORM在我的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:18