Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Migration 如何从Zend Framework 3中的视图脚本访问服务?_Migration_Service Locator_Zend View_Zend Framework3_Zend Servicemanager - Fatal编程技术网

Migration 如何从Zend Framework 3中的视图脚本访问服务?

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

我有一个自定义的身份验证服务,在ZF2中,我访问该服务的方式如下:

应用程序/视图/布局/布局.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(); 

我完全同意你的看法!我完全同意你的看法!