3

I work Yii with doctrine 2. I have a problem, datetime in doctrine 2 is an object of DateTime class, and I can't update it with regular methods of CHtml or form.

How can I add new item in CHtml that can handle this situation.

--Best Regards Moe Far

Moe Far
  • 2,742
  • 2
  • 23
  • 41

1 Answers1

2

You can extend the CHtml class and add your own functions. The code should look something like this:

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

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

You can then use MyHtml::myFunction() and also use all the standard CHtml functions.

Take a look at this question for more info on extending classes in Yii: How to extend Yii framework classes and where to place the files

Community
  • 1
  • 1
Jap Mul
  • 17,398
  • 5
  • 55
  • 66
  • Thnx jagsler, I also want to make a new element in cactiveform to manage my data model with it. Do you have any idea about that? – Moe Far Feb 25 '14 at 16:27
  • No problem. If this is the correct answer you should mark it btw. Not really sure what you want to do with de `CActiveForm` but you can also extend this class and create `MyActiveForm` (or some name) and add your own logic. – Jap Mul Feb 26 '14 at 07:50