1

I try to use identity view helper in my layout.phtml

$this->identity();

but get this error:

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

1 Answer 1

2

Did you actually setup Zend-Authentication and registered it within your services of the ServiceManager?

Because the factory for the IdentityHelper will set the AuthenticationService.

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

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

Register the AuthenticationService within your Applications module.config.php:

'service_manager' => [
    'factories' => [
        \Zend\Authentication\AuthenticationService::class => \Application\Service\Factory\AuthenticationServiceFactory::class,
    ]
],

Create a factory for your AuthenticationService where you tell the service which adapter to use on how to check if the identity is valid. See https://docs.zendframework.com/zend-authentication/intro/#usage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.