我尝试在我的layout.phtml中使用身份视图帮助程序
$this->identity();
但出现此错误:
No AuthenticationServiceInterface instance provided in vendor\zendframework\zend-view\src\Helper\Identity.php on line 38
答案 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