[英]how can I reference Zend_Db_Table_Row properties inside it's object
I've got a problem, im using Zend_Db_Table_Row to model my application. 我有一个问题,我使用Zend_Db_Table_Row来建模我的应用程序。 I have an object with a money property called value. 我有一个名为value的money属性的对象。 It is storred as int in the database. 它在数据库中作为int存储。 What i want to do, is to return Zend_Currency object each time something calls for this property. 我想要做的是,每次调用此属性时都返回Zend_Currency对象。 Like this: 像这样:
$prepayment = Zend_Db_Table_Row
$currency = $prepayment->value; // should fetch Zend_Currency instead of plain int.
I've tried to acces $this->value inside Row class but it seems not work. 我试图在Row类中访问$ this-> value但它似乎不起作用。 How can I overwrite getters for an property inside Row object? 如何在Row对象中覆盖属性的getter? Any idea? 任何想法?
One way to do this is to create a view helper to convert your int value to aa Zend_Currency before displaying it : 一种方法是创建一个视图助手,在显示之前将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);
}
}
and to display it in your view do : 并在您的视图中显示它:
echo $this->currency($my_value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.