我猜当你说I do not want to use replacement function
你的意思是这是很费力的做str_replace
每次调用辅助时间。解决办法是用你自己的替换助手。这里有一个快速如何
首先在Module.php创建自己的助手,其扩展了现有的帮手,如果需要处理更换...
<?php
namespace Application\View\Helper;
use Zend\I18n\View\Helper\CurrencyFormat;
class MyCurrencyFormat extends CurrencyFormat
{
public function __invoke(
$number,
$currencyCode = null,
$showDecimals = null,
$locale = null
) {
// call parent and get the string
$string = parent::__invoke($number, $currencyCode, $showDecimals, $locale);
// format to taste and return
if (FALSE !== strpos($string, 'TRY')) {
$string = str_replace('TRY', 'TL', $string);
}
return $string;
}
}
然后,实施ViewHelperProviderInterface,并为其提供与你的帮手的详细信息
//Application/Module.php
class Module implements \Zend\ModuleManager\Feature\ViewHelperProviderInterface
{
public function getViewHelperConfig()
{
return array(
'invokables' => array(
// you can either alias it by a different name, and call that, eg $this->mycurrencyformat(...)
'mycurrencyformat' => 'Application\View\Helper\MyCurrencyFormat',
// or if you want to ALWAYS use your version of the helper, replace the above line with the one below,
//and all existing calls to $this->currencyformat(...) in your views will be using your version
// 'currencyformat' => 'Application\View\Helper\MyCurrencyFormat',
),
);
}
}
当你用TL代替TRY会发生什么? – AmazingDreams 2013-02-26 22:41:58
它不打印任何想法。由于助手使用INTL扩展,它只接受货币的ISO代码。 – Valour 2013-02-26 22:44:46
'TL'不会是官方的ISO 4217货币代码指示器,因此无法使用。如果真的如此,我会认为这是PHP核心中的一个错误。我不知道火鸡,但如果它真的TL而不是TRY,那么你应该提交一份错误报告! – Sam 2013-02-26 22:47:02