在向bjyauthorize添加警卫时接收白屏

时间:2014-09-15 06:12:43

标签: php mysql zend-framework2 zend-db bjyauthorize

我是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 &#下的字段引用也不正确34; (" 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向我显示该用户的正确角色。所以这至少是积极的。

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

1 个答案:

答案 0 :(得分:0)

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

bjyauthorize附带的数据库架构具有字段&#34; roleId &#34; - 在上面的代码中,我没有考虑区分大小写并且有#34; roleid &#34;。改变了,一切都很完美。