How to adapt ZfcUser / zfcuserDoctrineORM modules in my project using doctrine 2 using annotations?

I am writing from Argentina, forgive my English a little. Im having some problems with the ZfcUser and zfcuserDoctrineORM . I need to integrate them into my project. Im working with Zend framework 2, doctrine 2.3 and postgreSQL, and this is the first time I work with these tools. For this 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',
           ),
        ),
     );

To map my database, I used the annotations with the doctrine, and I have my own user created in my module.

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

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

In 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 the zfcuserDoctrineORM module works with XML. Can modules adapt to work with annotations? If possible, how can I adapt the user of my object to this module? What archives should I change?

+6
source share
2 answers

You do not need to adapt ZfcUserDoctrineORM to use annotation mappings. DoctrineORMModule supports mixed mappings natively (it's your choice to decide which entities should map to which drivers). About the ZfcUser configuration, I personally did not change it at all (I just did some overrides for what ZfcUserDoctrineORM does).

  • remove config/autoload/zfcuser.global.php (you don't need it)
  • remove config/autoload/zfcuserdoctrineorm.global.php
  • in the module that defines your custom object, use the following command if you want to override the ZfcUserDoctrineOrm annotation driver (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 versions 0.1.x ZfcUserDoctrineORM

+6
source

The solution from Ocramius worked for me with a few changes (thank you very much!),

Firstly, it seems that there is an error in the latest version of the doctrine module (I got the error message “when zfcuser_doctrine_em is required, the service cannot be found”), so I had to go back to 0.7 instead. I attached my composer.json configuration below,

 "doctrine/dbal": "2.3.*", "doctrine/common": "2.3.*", "doctrine/doctrine-module": "0.7.*", "doctrine/doctrine-orm-module": "0.7.*", "doctrine/orm": "2.3.*", "zf-commons/zfc-user": "0.1.*", "zf-commons/zfc-user-doctrine-orm": "0.1.*", 

In the following case, I had to save zfcuser.global.php with the following configuration option, 'user_entity_class' => 'Application\Entity\User', This is necessary if you want to override the default object with your own.

Hope this helps.

+1
source

All Articles