我尝试在Cakephp中设置一个生活空间的数字格式,它应该看起来像这样:" 100,00m²"因为我经常使用这种格式,所以我想在我的AppController beforeFilter()中创建一个默认格式:
CakeNumber::addFormat('AREA', array(
'thousands' => ' ',
'decimals' => ',',
'places' => 2,
'before' => false,
'after' => ' m²'
));
在我的视图文件中,我调用:echo $this->Number->currency($area, 'AREA');
问题:'after'不适用,所以它缺少"m²",只有" 100,000 "显示。
我知道生存空间不是货币,但它看起来是定义可重复使用的数字格式的最佳选择。
编辑解决方案:感谢Mantas:
CakeNumber::addFormat('AREA', array('thousands' => ' ',
'decimals' => ',',
'places' => 2,
'wholeSymbol' => ' m²',
'wholePosition' => 'after'
));
你应该设置
[
'wholeSymbol' => ' m²',
'wholePosition' => 'after',
]