Migration 如何从Zend Framework 3中的视图脚本访问服务?
我有一个自定义的身份验证服务,在ZF2中,我访问该服务的方式如下:Migration 如何从Zend Framework 3中的视图脚本访问服务?,migration,service-locator,zend-view,zend-framework3,zend-servicemanager,Migration,Service Locator,Zend View,Zend Framework3,Zend Servicemanager,我有一个自定义的身份验证服务,在ZF2中,我访问该服务的方式如下: 应用程序/视图/布局/布局.phtml $authenticationService = $this->getHelperPluginManager() ->getServiceLocator() ->get('AuthenticationService'); $currentIdentity = $authenticationService->getIdentity(); 现在,Zen
应用程序/视图/布局/布局.phtml
$authenticationService = $this->getHelperPluginManager()
->getServiceLocator()
->get('AuthenticationService');
$currentIdentity = $authenticationService->getIdentity();
现在,Zend\ServiceManager#getServiceLocator()已被弃用
如何在ZF3中的视图脚本(或在本例中的具体布局)中获得可用的服务?解决方案是在
onBootstrap(…)
中分配一个全局视图变量:
另一个(可能更好/更干净的)解决方案是使用
ViewHelper
。另请参见。解决方案是在onBootstrap(…)
中指定一个全局视图变量:
另一个(可能更好/更干净的)解决方案是使用
ViewHelper
。另请参见。为此目的,已有
正如文件所说
// Use it any .phtml file
// return user array you set in AuthenticationService or null
$user = $this->identity();
为此目的,已经有了 正如文件所说
// Use it any .phtml file
// return user array you set in AuthenticationService or null
$user = $this->identity();
我完全同意你的看法!我完全同意你的看法!