Reputation: 1645
I did read this answer ZF2, what's the best practice for working with Vendor Module's Form classes?. So it's mainly clear how to change configurable parts of the vendor module, but what do I do if in zfcUser module I want to add new functionality to the Entity/User?
In short I want to check user role, I've added to DB field, what's the best way to do that? Maybe I should do it somewhere else and not in zfcUSer if so where?
Upvotes: 2
Views: 1355
Reputation: 1645
I won't be claiming this is a best practice, but this is how I managed to handle the situation! First - big thanks to answer in this question ZF2: Custom user mapper for ZfcUser module.
So, I did:
zfcUser/Entity
in zfc-user.global.php
autoload:
'zfcuser' => array( 'tableName' => 'users', 'user_entity_class' => 'Application\Entity\User' ),
Entity\User
, Mapper\User
and Mapper\Hydrator
into my src/Application
Entity and Mapper subfolders.Application\Entity
and Application\Mapper
Added this configuration to getServiceConfig
function of my Module.php
:
'factories' => [
'zfcuser_user_mapper' => function ($sm) {
$mapper = new Mapper\User();
$mapper->setDbAdapter($sm->get('Zend\Db\Adapter\Adapter'));
$mapper->setEntityPrototype(new Entity\User());
$mapper->setHydrator(new Mapper\UserHydrator());
return $mapper;
},
]
ZfcUSer
and started my Entity\User
as extends \ZfcUser\Entity\User implements \ZfcUser\Entity\UserInterface
.Upvotes: 2
Reputation: 11447
Take a look at ZfcUser/config/zfcuser.global.php.dist
In there you'll see this
/**
* User Model Entity Class
*
* Name of Entity class to use. Useful for using your own entity class
* instead of the default one provided. Default is ZfcUser\Entity\User.
* The entity class should implement ZfcUser\Entity\UserInterface
*/
//'user_entity_class' => 'ZfcUser\Entity\User',
The directions are straightforward, copy the file to ./config/autoload/zfcuser.global.php
, makes sure your entity class implements the ZfcUser\Entity\UserInterface
, uncomment that line and change the FQCN to match the entity you want to use instead.
Upvotes: 6