我对ZF2和bjyauthorize还不熟悉,所以我希望这是一个愚蠢的错误:D
我已经成功地设置了ZF2 skeleton应用程序和zfcUser,并且正在尝试将bjyAuthorize添加到组合中。我也在使用Zend/Db连接类型到mySQL-NOT docine(:D)。我使用的版本是PHP(5.5)、ZF2(2.3.*)、zfcUser(1.2.1)、bjyAuthorize(1.4.0)。
我已经按照GitHub Readme中的说明进行了操作。很快我就意识到,示例“bjyauthorize.global.php”文件包含的设置太多(作为示例),并且在“\bjyauthorize\Provider\Role\ZendDb::class”(“Role\u id”s/b“roleid”)下有一个不正确的字段引用。
基本上,只要我在我的配置文件中取消对基于路由或基于控制器的保护的注释(我不打算两者都做-只想有一个工作),当我试图访问我的骨架应用程序主页时,我就会得到一个白色的屏幕-没有错误消息是有帮助的。我担心这是一个PHP语法错误。
我还包括ZendDeveloperTools,当我得到这个错误时,甚至页脚上的工具栏都没有出现。
这是我的配置文件:
<?php
return [
'bjyauthorize' => [
// set the 'guest' role as default (must be defined in a role provider)
'default_role' => 'guest',
/* this module uses a meta-role that inherits from any roles that should
* be applied to the active user. the identity provider tells us which
* roles the "identity role" should inherit from.
*
* for ZfcUser, this will be your default identity provider
*/
'identity_provider' => \BjyAuthorize\Provider\Identity\ZfcUserZendDb::class,
/* role providers simply provide a list of roles that should be inserted
* into the Zend\Acl instance. the module comes with two providers, one
* to specify roles in a config file and one to load roles using a
* Zend\Db adapter.
*/
'role_providers' => [
// this will load roles from the user_role table in a database
// format: user_role(role_id(varchar], parent(varchar))
\BjyAuthorize\Provider\Role\ZendDb::class => [
'table' => 'user_role',
'identifier_field_name' => 'id',
'role_id_field' => 'roleid',
'parent_role_field' => 'parent_id',
],
],
/* Currently, only controller and route guards exist
*
* Consider enabling either the controller or the route guard depending on your needs.
*/
'guards' => [
/* If this guard is specified here (i.e. it is enabled], it will block
* access to all controllers and actions unless they are specified here.
* You may omit the 'action' index to allow access to the entire controller
*/
// \BjyAuthorize\Guard\Controller::class => [
// ['controller' => 'zfcuser', 'roles' => ['guest']],
// ['controller' => ['Application\Controller\Index'], 'roles' => ['guest']],
// ],
// /* If this guard is specified here (i.e. it is enabled], it will block
// * access to all routes unless they are specified here.
// */
// \BjyAuthorize\Guard\Route::class => [
// ['route' => 'zfcuser', 'roles' => ['user']],
// ['route' => 'zfcuser/logout', 'roles' => ['user']],
// ['route' => 'zfcuser/login', 'roles' => ['guest']],
// ['route' => 'zfcuser/register', 'roles' => ['guest']],
// // Below is the default index action used by the ZendSkeletonApplication
// ['route' => 'home', 'roles' => ['guest', 'user']],
// ],
],
],
];
当我在没有警卫的情况下按照上面的代码运行时,我可以通过site/user/login登录,Zend Dev工具栏显示该用户的正确角色。所以这至少是积极的。
很高兴提供任何进一步的信息或设置-只是尝试学习。
最佳答案
好吧,我现在觉得很傻。
bjyaauthorize附带的DB模式具有字段“roleId”-在上面的代码中,我没有考虑区分大小写,而是具有“roleId”。改变了它,一切都很好。