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

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

问题描述

我是在阿根廷写信的,请原谅我的英语少.我在模块 ZfcUserzfcuserDoctrineORM 上遇到了一些问题.我需要将它们集成到我的项目中.我正在使用 Zend 框架 2、doctrine 2.3 和 postgreSQL,这是我第一次使用这些工具.出于这个原因,有很多东西我不太擅长,我的 /config/application.config.php 中包含所有模块,并且我的连接在 中的数据库中配置>/config/autoload/local.php

Local.php

<前>返回数组('学说' => 数组('连接' => 数组('orm_default' => 数组('driverClass' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver','参数' => 数组('主机' => '本地主机','端口' => '5432','用户' => 'postgres','密码' => 'postgres','dbname' => 'ministerio',)))),);

application.config.php

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

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

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

进入zfcuser.global.php

<前>'zend_db_adapter' => 'Zend\Db\Adapter\Adapter',//这个应该注释吗?'user_entity_class' => 'Reeser\Entity\User','login_redirect_route' => 'Reeser/index/index.phtml',返回数组('zfcuser' => $settings,//我如何配置这段代码?'service_manager' => 数组('别名' => 数组('zfcuser_zend_db_adapter' => (isset($settings['zend_db_adapter'])) ?$settings['zend_db_adapter']: 'Zend\Db\Adapter\Adapter',),),);

进入zfcuserdoctrineorm.global.php

<前>返回数组('学说' => 数组('司机' => 数组('zfcuser_driver' => 数组('class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver','缓存' => '数组','路径' => 数组(__DIR__ .'/../src/Reeser/Entity')),'orm_default' => 数组('司机' => 数组('ZfcUser\Entity' => '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' =>大批(//自定义路径'类' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver','路径' =>数组(__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' => '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.

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' => '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',
            ),
         ),
    );  

Into 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'
                )
            )
         )
      ),
    );

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' => '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,
    ),
    

This should work for the 0.1.x versions of ZfcUserDoctrineORM

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

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