Php Can';我不明白为什么我能';不要调用方法

Php Can';我不明白为什么我能';不要调用方法,php,zend-framework,localization,zend-framework2,Php,Zend Framework,Localization,Zend Framework2,Zend 2框架,layout.phtml 在这里,我可以用$this->translate('key')来翻译字符串,但我不能用$this->getLocale()来获取区域设置。为什么?它们都是来自同一个类转换器的方法!我得到的只是一个例外: 致命错误:未捕获异常 带有消息的“Zend\ServiceManager\Exception\ServiceNotFoundException” 'Zend\View\HelperPluginManager::get无法获取或创建 中的getLocal

Zend 2框架,layout.phtml

在这里,我可以用$this->translate('key')来翻译字符串,但我不能用$this->getLocale()来获取区域设置。为什么?它们都是来自同一个类转换器的方法!我得到的只是一个例外:

致命错误:未捕获异常 带有消息的“Zend\ServiceManager\Exception\ServiceNotFoundException” 'Zend\View\HelperPluginManager::get无法获取或创建 中的getLocale'实例 D:\Dropbox\Projects\www\linksync\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php 在线496

这是我的module.config.php(应用程序模块)


原因是Translate是一个视图助手(),它通过
$this->
提供。您需要在视图/布局中使用Zend_Locale对象,如下所示:

<?php
$locale = new Zend_Locale();

// Actual locale
print $locale->toString();

// if locale is 'de_AT' then 'de' will be returned as language
print $locale->getLanguage();

// if locale is 'de_AT' then 'AT' will be returned as region
print $locale->getRegion();

很可能在某个地方有区域设置,但是无法通过
$this->getLocale()
访问该区域设置。你能提供任何证明它应该在那里的参考资料吗?我不能!上面写的所有内容都是我的假设,因为我不知道访问当前语言环境的任何其他方法。还有别的办法吗?我搜索了,但没有找到任何有用的:\n我也不知道,我只能疯狂地猜测,我会说我会先得到翻译,然后在翻译中查找区域设置。这是我首先尝试实现的,但任何检索翻译实例的尝试都会以空对象结束:\n无论如何,由于翻译是通过视图帮助器实现的,所以我将尝试编写一个自定义的来获取区域设置。我将不断更新此线程,并报告任何有用的解决方法。Zend Framework 2中不再支持Zend_语言环境!它已被Translator类取代。无论如何,非常感谢您对View Helper的解释,您确认了我的怀疑。在这一点上,我将尝试实现一个自定义视图助手来实现我的目标。
<?php
$locale = new Zend_Locale();

// Actual locale
print $locale->toString();

// if locale is 'de_AT' then 'de' will be returned as language
print $locale->getLanguage();

// if locale is 'de_AT' then 'AT' will be returned as region
print $locale->getRegion();