2012-11-01 23:00
浏览 31


I`ve added module ZfcUser on my Zend Framework 2 application. But I have to use existing database table, which has slightly different column names than the default table structure for ZfcUser.

In ZfcUser wiki page it says that it is possible to use custom mapper if my model doesn`t conform to the provided interface. And since my database table is different than default, my user entity class is also different than standard ZfcUser\Entity\User. But I can tell ZfcUser to work with my own class easily by overriding setting in file config/autoload/

'user_entity_class' => 'MyApp\Entity\MyUser',

But I`ve not found an easy way to tell ZfcUser to use my mapper class so far.

I have only found that the mapper is created by ZfcUser\Module::getServiceConfig() inside which, I can see the mapper is returned from its factory function:

// ...
public function getServiceConfig()
    return array(
    // ...
        'factories' => array(
            // ...
            'zfcuser_user_mapper' => function ($sm) {
                $options = $sm->get('zfcuser_module_options');
                $mapper = new Mapper\User();
                $entityClass = $options->getUserEntityClass();
                $mapper->setEntityPrototype(new $entityClass);
                $mapper->setHydrator(new Mapper\UserHydrator());
                return $mapper;
            // ...

Is there a way to make ZfcUser to use my custom user mapper class?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题