zendframework 3-身份视图助手错误

时间:2018-11-02 11:20:09

标签: zend-framework3

我尝试在我的layout.phtml中使用身份视图帮助程序

$this->identity();

但出现此错误:

No AuthenticationServiceInterface instance provided in  vendor\zendframework\zend-view\src\Helper\Identity.php on line 38

1 个答案:

答案 0 :(得分:0)

您是否真的设置了Zend-Authentication并将其注册在services的{​​{1}}中?

因为ServiceManager的工厂将设置IdentityHelper

请参阅:https://github.com/zendframework/zend-mvc-plugin-identity/blob/1.1.0/src/IdentityFactory.php#L27-L31

AuthenticationService

在“应用程序” module.config.php中注册AuthenticationService:

    if ($container->has(AuthenticationService::class)) {
        $plugin->setAuthenticationService($container->get(AuthenticationService::class));
    } elseif ($container->has(AuthenticationServiceInterface::class)) {
        $plugin->setAuthenticationService($container->get(AuthenticationServiceInterface::class));
    }

为您的AuthenticationService创建一个工厂,在此告诉服务使用哪个适配器来检查身份是否有效。参见https://docs.zendframework.com/zend-authentication/intro/#usage