请教 zii CJuiDatePicker 的使用方法




<?php

                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(

                        'model' => $model,

                        'language' => 'zh_cn',

                        'attribute' => 'history_date',

                        'options' => array(

                            'showAnim' => 'fold',

                            'dateFormat' => 'yy-mm-dd',

                        ),

                    ));

                    ?>



数据库字段 history_date 为 Integer 类型,通过 beforeValidate() 事件将 2009-11-30 类似的日期转换成 222222 类似的整型数据保存入库。新增是没有问题,但是编辑的话,上面的代码不会提取 history_date 字段内容,而是默认为当前日期。

问题一:

如何让以上的代码自动读取模型中的 history_date 内容?

问题二:

假设现在读取正常,而 history_date 的数据未经处理的话,是类似于 222222 之类的数据,而 DataPicker 要求的是”2009-11-30“这样的数据,这个应该怎么处理?我尝试用 getHistory_date 返回数据,但是未果?不知如何处理了,有知道的兄弟麻烦解答一下。谢谢。

同问 :rolleyes:

你可以通过getter/setter定义一个新的属性:getHistoryDateText, setHistoryDateText。它们对history_date进行操作。

然后对historyDateText进行输入,而不是history_date。这样可以不用写beforeValidate之类的转换。

貌似这样也可以




public function gethistory_date() {

    return date('Y-m-d', $this->history_date);

}