3

我用学说 2 工作 Yii。我有一个问题,学说 2 中的日期时间是 DateTime 类的对象,我不能用 CHtml 或表单的常规方法更新它。

如何在 CHtml 中添加可以处理这种情况的新项目。

——最好的问候 Moe Far

4

1 回答 1

2

您可以扩展CHtml该类并添加您自己的功能。代码应如下所示:

class MyHtml extends CHtml {
    // add you own logic or override CHtml functions

    public static function myFunction() {
        return 'yeah!'; 
    }
}

然后,您可以MyHtml::myFunction()使用所有标准 CHtml 函数。

看看这个问题,了解更多关于在 Yii 中扩展类的信息:How to extend Yii framework classes and where to place the files

于 2014-02-25T16:07:40.140 回答