首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >zfcuser +规则自定义用户实体

zfcuser +规则自定义用户实体
EN

Stack Overflow用户
提问于 2017-01-11 05:42:57
回答 1查看 255关注 0票数 1

我正在与zf2和zfcuser模块一起做一个项目。我已经创建了一个自定义用户模块,它扩展了zfcuser,也是用户表的自定义实体,并为集成做了所有必要的更改。但我的问题是,当尝试对自己进行身份验证时,我得到了这个错误:

代码语言:javascript
复制
An alias "Zend\Db\Adapter\Adapter" was requested but no service could be found.

当zfcuser_user_mapper尝试更改适配器时,就会发生这种情况。

注意:我不太清楚为什么需要使用Zend \ Db \ Adapter \ Adapter,因为我使用的是working。

这是自定义用户模块的module.php中的代码。

代码语言:javascript
复制
    public function getServiceConfig() {
    return [
        'aliases' => array(
            'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),
        'factories' => [
            'usuario_login_form' => 'Usuario\Factory\Form\Login',
            'usuario_registro_form' => 'Usuario\Factory\Form\Register',
            'usuario_user_service' => 'Usuario\Factory\Service\UserFactory',
            //'usuario_user_mapper' => 'Usuario\Factory\Mapper\User',
            'usuario_auth_service' => 'Usuario\Factory\AuthenticationService',
            'Usuario\Authentication\Adapter\Db' => 'Usuario\Factory\Authentication\Adapter\DbFactory',
            'Usuario\Authentication\Storage\Db' => 'Usuario\Factory\Authentication\Storage\DbFactory',
            //'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\Adapter',
            'usuario_user_mapper' => function ($sm) {
                $mapper = new Mapper\User();
                $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
                $mapper->setEntityPrototype(new ORM\Entity\Usuarios());
                $mapper->setHydrator(new \ZfcUser\Mapper\UserHydrator());
                return $mapper;
            },
        ]
    ];
}

这是我的global.php文件

代码语言:javascript
复制
return array(
'doctrine' => array(
    'connection' => array(
        'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
            'params' => array(
                'host' => 'localhost',
                'port' => '3306',
                'user' => 'root',
                'password' => 'toor',
                'dbname' => 'deporte',
            )
        )
    )
),

);

这是我的module.config.php文件:

代码语言:javascript
复制
    'controllers' => array(
),
'doctrine' => array(
    'driver' => array(
        // overriding zfc-user-doctrine-orm's config
        'usuario_entity' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'paths' => __DIR__ . '/../src/Usuario/ORM/Entity',
        ),
        'orm_default' => array(
            'drivers' => array(
                'Usuario\ORM\Entity' => 'usuario_entity',
            ),
        ),
    ),
),
'zfcuser' => array(
    'auth_adapters' => array(100 => 'Usuario\Authentication\Adapter\Db'),
    // telling ZfcUser to use our own class
    'user_entity_class' => 'Usuario\ORM\Entity\Usuarios',
    // telling ZfcUserDoctrineORM to skip the entities it defines
    'enable_default_entities' => false,
),

我感谢你的帮助,我已经被这个错误困扰了好几天了。非常感谢,请原谅我的英语。

EN

回答 1

Stack Overflow用户

发布于 2017-01-12 12:12:39

如果你想要改变实体并且想要使用你的,那么使用以下步骤:如果zfcuser.global.php文件被放置在配置/自动加载文件夹中(如果不是,那么你可以从zfcuser模块复制If。

在这个全局文件中,搜索"user_entity_class“键并定义您自己实体class.By,它使用默认值

代码语言:javascript
复制
'user_entity_class' => 'ZfcUser\Entity\User',

就像我将它用于员工实体一样

代码语言:javascript
复制
'user_entity_class' => 'Employee\Entity\Employee',

在这个实体中,您需要实现UserInterface。

代码语言:javascript
复制
use ZfcUser\Entity\UserInterface;
/**
 * Employee
 *
 * @ORM\Table(name="employee")
 * @ORM\Entity(repositoryClass="Employee\Repository\EmployeeRepository")
 */
class Employee implements UserInterface {

}

如果要覆盖数据库适配器,则需要执行以下步骤:

代码语言:javascript
复制
'service_manager' => array(
        'invokables' => array(
            'ZfcUser\Authentication\Adapter\Db' => 'Employee\Authentication\Adapter\Db',
        ),
    ),

在此文件中,您需要扩展和实现。

代码语言:javascript
复制
namespace Employee\Authentication\Adapter;

use InvalidArgumentException;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\Crypt\Password\Bcrypt;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\Session\Container as SessionContainer;
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthenticationEvent;
use ZfcUser\Entity\UserInterface as UserEntity;
use ZfcUser\Mapper\HydratorInterface as Hydrator;
use ZfcUser\Mapper\UserInterface as UserMapper;
use ZfcUser\Authentication\Adapter\AbstractAdapter;
use ZfcUser\Options\AuthenticationOptionsInterface as AuthenticationOptions;

class Db extends AbstractAdapter implements ServiceManagerAwareInterface
{

}

有关更多信息,请访问zfcuser wiki:https://github.com/ZF-Commons/ZfcUser/wiki

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41578955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档