【问题标题】:Add BjyAuthorize Roles (using ZfcUser and Doctrine)添加 BjyAuthorize 角色(使用 ZfcUser 和 Doctrine)
【发布时间】:2013-02-13 18:04:00
【问题描述】:

我正在尝试在 ZF2 中使用 bjy-authorize、zfcUser 和 zfc-user-doctrine-orm。 我安装了有关手册的所有模块。要将 bjyAuthorize 与教义一起使用,我使用了本教程 https://github.com/bjyoungblood/BjyAuthorize/pull/62

如何创建新角色以及如何将它们链接到用户?

上面的教程使用这个来配置role_providers:

    'BjyAuthorize\Provider\Role\DoctrineEntity' => array(
                                        'role_entity_class' => 'Material\Entity\Role',
                                    ),

在 BjyAuthorize 的其他一些配置文件中,这是通过

    // this will load roles from the user_role table in a database
    // format: user_role(role_id(varchar), parent(varchar))
    'BjyAuthorize\Provider\Role\Doctrine' => array(
                            'table'             => 'user_role',
                            'role_id_field'     => 'role_id',
                            'parent_role_field' => 'parent',
     ),

这些配置有什么区别?

谢谢!

【问题讨论】:

  • 检查./data/Role.php.disp 您需要将其添加到您的代码中,然后使用教义-CLI 安装它或手动创建表。添加新角色然后您需要为其创建表单或手动将其添加到数据库中。添加角色不是授权模块的功能;)
  • 我很困惑,因为我认为roleId是一个整数,所以我不知道如何将配置文件中的角色名称与数据库中的Id联系起来。但是 roleId 在 VarChar 中,所以我想我只是使用与配置文件中的 roleId 相同的名称。我不是在寻找添加新角色的功能,我只是不知道如何手动添加它们;)所以感谢您的帮助!

标签: doctrine-orm zend-framework2 zfcuser


【解决方案1】:

请避免使用BjyAuthorize\Provider\Role\Doctrine,因为我很快就会弃用它。

继续使用新引入的BjyAuthorize\Provider\Identity\AuthenticationDoctrineEntity

BjyAuthorize\Provider\Role\Doctrine 正在使用直接 SQL 查询,在使用 Doctrine 时并不建议这样做(主要是可移植性)

【讨论】:

  • 好的,谢谢!我将使用 DoctrineEntity。
猜你喜欢
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
相关资源
最近更新 更多