【问题标题】:Fatal error: Uncaught exception in zfc-rbac quickstart致命错误:zfc-rbac 快速入门中未捕获的异常
【发布时间】:2015-02-21 03:40:10
【问题描述】:

我正在尝试遵循 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:\Users\Sama\Documents\NetBeansProjects\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:550

【问题讨论】:

    标签: zend-framework2


    【解决方案1】:

    尝试安装ZfcUser 并向module.config.php 添加别名,如doc 中所述

    'service_manager' => array(
        'aliases' => array(
            'Zend\Authentication\AuthenticationService' =>'zfcuser_auth_service'  
        )  
     )
    

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 2013-07-07
      • 2015-06-10
      • 2015-06-20
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多