duanchao1002 2010-05-16 10:36
浏览 40
已采纳

如何格式化Zend_db Rowset输出?

I have a model which is referenced to a table registries extending Zend_Db and some methods which bascially uses fetchAll() all the time.

What happens is: my table has a DATE field and I'd like it to output already formated when I call $row->reg_date. Is it possible by doing something in the model or do I have to manually format?

  • 写回答

2条回答 默认 最新

  • doupao2277 2010-05-16 10:48
    关注

    You've got a couple of options:

    • Overwrite Zend_Db_Table_Row_Abstract::__get() in your table when asking for the reg_date
    • Format it in the view with your own view helper, something like <?= $this->formatDate($this->row->reg_date, 'fancy'); ?>

    Doctrine probably has the answer you would like, the following is cut from http://www.doctrine-project.org/documentation/manual/1_2/en/introduction-to-models#generating-models:

    class User extends BaseUser
    {
        public function setPassword($password)
        {
            return $this->_set('password', md5($password));
        }
    }
    
    $user = new User();
    $user->username = 'jwage';
    $user->password = 'changeme';
    
    echo $user->password; // outputs md5 hash and not changeme
    

    If I were you, I'd go with the view helper-option. You could add custom CSS there and have it all ready to go. If you'd need it changed, you'd change it in one place and your application's renewed.

    Besides, if you ever wanted to do something with the date (compare it to another date, get just the month, localize it, etc.) you want a clean starting point which is what you'd store in the database (i.e. 2010-05-16 or 2010-05-16 16:55:00). Therefore: view settings belongs in the view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面