【发布时间】:2014-09-15 06:12:43
【问题描述】:
我是 ZF2 和 bjyauthorize 的新手 - 所以在某种程度上希望这是我的一个愚蠢的错误:D
我已成功设置 ZF2 框架应用程序和 zfcUser,并尝试将 bjyAuthorize 添加到组合中。我也在使用 Zend/Db 连接类型到 mySQL - NOT DOCTRINE (: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_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 ToolBar 会显示该用户的正确角色。所以这至少是积极的。
很高兴提供任何进一步的信息或设置 - 只是想学习。
【问题讨论】:
-
在“玩”过设置后,我发现如果我替换代码:\BjyAuthorize\Provider\Role\ZendDb::class=> ['table' =>'user_role', 'identifier_field_name' => 'id', 'role_id_field' => 'roleid', 'parent_role_field' => 'parent_id', ], with: \BjyAuthorize\Provider\Role\Config::class=> ['guest' => [], 'user' => ['children' => [ 'admin' => [], ]], ], 它工作正常 - 所以问题就变成了为什么它无法从数据库中获取角色.. ..
标签: php mysql zend-framework2 zend-db bjyauthorize