我猜當你說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