0
I’m having trouble displaying the logged-in user name using view helper.
Module:
public function getViewHelperConfig() {
return array(
'invokables' => array(
'UserIdentity' => new View\Helper\UserIdentity()
)
);
}
Useridentity:
use Zend\View\Helper\AbstractHelper;
use Zend\Authentication\AuthenticationService,
Zend\Authentication\Storage\Session as SessionStorage;
class UserIdentity extends AbstractHelper {
protected $authService;
public function getAuthService() {
return $this->authService;
}
public function __invoke($namespace = null) {
$sessionStorage = new SessionStorage($namespace);
$this->authService = new AuthenticationService;
$this->authService->setStorage($sessionStorage);
if ($this->getAuthService()->hasIdentity()) {
return $this->getAuthService()->getIdentity();
} else {
return false;
}
}
}
View:
$usuario = $this->UserIdentity('Usuario');