如何使用注释在我的项目中使用学说 2 调整模块 ZfcUser/zfcuserDoctrineORM? [英] How to adapt modules ZfcUser/ zfcuserDoctrineORM in my project with doctrine 2 using annotations?

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

问题描述

我是从阿根廷写的,请原谅我的英语小.我在使用 ZfcUserzfcuserDoctrineORM 模块时遇到了一些问题.我需要将它们集成到我的项目中.我正在使用 Zend 框架 2、教义 2.3 和 postgreSQL,这是我第一次使用这些工具.出于这个原因,有很多事情我不能很好地掌握,我的所有模块都包含在我的 /config/application.config.php 中,并且我的连接是在我的数据库中配置的 /config/autoload/local.php

Local.php

<上一页>返回数组('教义' => 数组('连接' => 数组('orm_default' =>数组('driverClass' => 'DoctrineDBALDriverPDOPgSqlDriver','参数' => 数组('主机' => '本地主机','端口' => '5432','用户' => 'postgres','密码' => 'postgres','dbname' => 'ministerio',)))),);

application.config.php

<上一页>返回数组('模块' => 数组('应用','教义模块','DoctrineORMModule','Reeser',//我的模块名称'ZfcBase','Zfc用户','ZfcUserDoctrineORM',),'module_listener_options' =>数组('config_glob_paths' =>数组('config/autoload/{,*.}{global,local}.php',),'module_paths' =>数组('./模块','./小贩',),),);

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

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

进入zfcuser.global.php

<上一页>'zend_db_adapter' => 'ZendDbAdapterAdapter',//应该注释掉吗?'user_entity_class' => 'ReeserEntityUser','login_redirect_route' => 'Reeser/index/index.phtml',返回数组('zfcuser' => $settings,//我如何配置这段代码?'service_manager' =>数组('别名' => 数组('zfcuser_zend_db_adapter' => (isset($settings['zend_db_adapter'])) ?$settings['zend_db_adapter']: 'ZendDbAdapterAdapter',),),);

进入zfcuserdoctrineorm.global.php

<上一页>返回数组('教义' => 数组('驱动程序' => 数组('zfcuser_driver' =>数组('class' => 'DoctrineORMMappingDriverAnnotationDriver','缓存' => '数组','路径' => 数组(__DIR__ .'/../src/Reeser/Entity')),'orm_default' =>数组('驱动程序' => 数组('ZfcUserEntity' => 'zfcuser_driver')))),);

我看到模块 zfcuserDoctrineORM 与 XML 一起工作.该模块可以适应注释吗?如果这是可能的,我如何使我的实体用户适应这个模块?我应该修改哪些档案?

解决方案

你不需要适配 ZfcUserDoctrineORM 使用注释映射.DoctrineORMModule 原生支持混合映射(由您决定哪些实体与哪些驱动程序进行映射).关于ZfcUser的配置,我个人完全没有修改(我只是做了一些覆盖关于 ZfcUserDoctrineORM 的作用).

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

    //实体映射'教义' =>大批('司机' =>大批('zfcuser_entity' =>大批(//自定义路径'类' =>'DoctrineORMMappingDriverAnnotationDriver','路径' =>数组(__DIR__ . '/../src/YourModule/Entity'),),'orm_default' =>大批('司机' =>大批('你的模块实体' =>'zfcuser_entity',),),),),//ZfcUser 特定配置'zfcuser' =>大批('user_entity_class' =>'你的模块实体用户','enable_default_entities' =>错误的,),

这应该适用于 ZfcUserDoctrineORM

0.1.x 版本

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' => 'DoctrineDBALDriverPDOPgSqlDriver',
                    '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.

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.

Into zfcuser.global.php

    'zend_db_adapter' => 'ZendDbAdapterAdapter',    // should this comment it?

    'user_entity_class' => 'ReeserEntityUser',

    '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']: 'ZendDbAdapterAdapter',
            ),
         ),
    );  

Into zfcuserdoctrineorm.global.php

    return array(
       'doctrine' => array(
          'driver' => array(
             'zfcuser_driver' =>array(
                 'class' => 'DoctrineORMMappingDriverAnnotationDriver',
                 'cache' => 'array',
                 'paths' => array(__DIR__ .'/../src/Reeser/Entity')
            ),

            'orm_default' =>array(
                'drivers' => array(
                    'ZfcUserEntity'  =>  'zfcuser_driver'
                )
            )
         )
      ),
    );

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 ?

解决方案

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. remove config/autoload/zfcuser.global.php (you don't need it)
  2. remove config/autoload/zfcuserdoctrineorm.global.php
  3. in the module defining your user entity, use following if you want to override the annotation driver of ZfcUserDoctrineOrm (assuming the file is in YourModule/config/module.config.php):

    // entity mappings
    'doctrine' => array(
        'driver' => array(
            'zfcuser_entity' => array(
                // customize path
                'class' => 'DoctrineORMMappingDriverAnnotationDriver',
                'paths' => array(__DIR__ . '/../src/YourModule/Entity'),
            ),
            'orm_default' => array(
                'drivers' => array(
                    'YourModuleEntity' => 'zfcuser_entity',
                ),
            ),
        ),
    ),
    
    // ZfcUser specific config
    'zfcuser' => array(
        'user_entity_class'       => 'YourModuleEntityUser',
        'enable_default_entities' => false,
    ),
    

This should work for the 0.1.x versions of ZfcUserDoctrineORM

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆