致命错误:zfc-rbac快速入门中的未捕获异常

时间:2015-02-21 03:40:10

标签: zend-framework2

我正在尝试遵循zfc-rbac教程。我马上被卡住了。我想我需要创建一个服务,但教程没有提示如何创建一个服务。

感谢您的帮助。

module.config.php
---------------
'service_manager' => array(
    'factories' => array(
        'Zend\Authentication\AuthenticationService' => function($sm) {
            // Create your authentication service!
        }
    ),

),
'zfc_rbac' => [
    'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW,
    'guards' => [
        'ZfcRbac\Guard\RouteGuard' => [
            //ADMIN ACCOUNT GUARDS
            'user' => ['admin-master'],
            'user/login' => ['guest'],
            'user/logout' => ['admin-master', 'merchant-worker', 'guest'],
            'user/register' => ['admin-master', 'merchant-admin', 'guest'],
            'user/change-password' => ['admin-master', 'merchant-worker'],
            'user/forgot-password' => ['guest'],
            //CUSTOMER ACCOUNT GUARDS
            'customer' => ['customer'],
        ]
    ],
    'identity_provider' => \RoleBasedUser\Service\AuthenticationService::class,
    'role_provider' => [
        'ZfcRbac\Role\ObjectRepositoryRoleProvider' => [
            'object_manager' => 'doctrine.entitymanager.orm_default',
            'class_name' => 'RoleBasedUser\Entity\HierarchicalRole',
            'role_name_property' => 'name'
        ]
    ],
    'redirect_strategy' => [
        'redirect_when_connected' => true,
        'redirect_to_route_connected' => 'home',
        'redirect_to_route_disconnected' => 'user/login',
        'append_previous_uri' => true,
        'previous_uri_query_key' => 'redirectTo'
    ],
]

Module.php
-------
public function onBootstrap(EventInterface $e) {
    $t = $e->getTarget();

    $t->getEventManager()->attach(
            $t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
    );
}

在我的控制器中,我有以下

AlbumController.php
-----------------
public function indexAction() {
    if (!$this->authorizationService->isGranted('delete')) {
        throw new UnauthorizedException();
    }
    return new ViewModel(array(
        'myfetch' => $this->getAlbumTable()->fetchAll(),
            )
    );
}

我的错误信息是:

  

致命错误:未捕获的异常   带有消息的'Zend \ ServiceManager \ Exception \ ServiceNotFoundException'   'Zend \ ServiceManager \ ServiceManager :: get无法获取或创建   用于RoleBasedUser \ Service \ AuthenticationService的实例   C:\用户\萨马\文件\的NetBeansProjects \ ZF2 \厂商\ zendframework \ zendframework \库\ Zend的\的ServiceManager \ ServiceManager.php:550

1 个答案:

答案 0 :(得分:0)

尝试安装ZfcUser并按照doc

中的说明为module.config.php添加别名
'service_manager' => array(
    'aliases' => array(
        'Zend\Authentication\AuthenticationService' =>'zfcuser_auth_service'  
    )  
 )