doulao7572 2012-03-25 16:09 采纳率: 0%
浏览 22
已采纳

如何在其对象中引用Zend_Db_Table_Row属性

I've got a problem, im using Zend_Db_Table_Row to model my application. I have an object with a money property called value. It is storred as int in the database. What i want to do, is to return Zend_Currency object each time something calls for this property. 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. How can I overwrite getters for an property inside Row object? Any idea?

  • 写回答

1条回答 默认 最新

  • douqiong8412 2012-03-25 19:45
    关注

    One way to do this is to create a view helper to convert your int value to a a Zend_Currency before displaying it :

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了