2

我是 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 自述文件中的说明进行操作。我很快就意识到示例“ 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 会向我显示该用户的正确角色。所以这至少是积极的。

很高兴提供任何进一步的信息或设置 - 只是想学习。

4

1 回答 1

0

好吧,所以我现在觉得很傻。

bjyauthorize 附带的数据库模式具有“ roleId ”字段 - 在我上面的代码中,我没有考虑区分大小写并且具有“ roleid ”。改变了这一点,一切都完美无缺。

于 2014-09-16T06:14:21.390 回答