我遇到了一个问题,我正在使用Zend_Db_Table_Row对我的应用程序进行建模。我有一个物体,它有一种叫做价值的货币属性。它在数据库中存储为int。我想做的是,每次有东西调用这个属性时,都返回Zend_Currency对象。像这样:
$prepayment = Zend_Db_Table_Row
$currency = $prepayment->value; // should fetch Zend_Currency instead of plain int.
我尝试在Row类中访问$this->值,但似乎不起作用。如何覆盖Row对象内属性的getter?知道吗?
实现这一点的一种方法是创建一个视图帮助程序,在显示int值之前将其转换为Zend_Currency:
class My_Helper_Currency extends Zend_View_Helper_Abstract
{
public function currency($value, $locale = 'fr_FR') {
$currency = new Zend_Currency($locale);
$value= $value+ 0.00;//to convert it to float
return $currency->toCurrency((float) $value);
}
}
并将其显示在您的视图中do:
echo $this->currency($my_value);