Search code examples
yiidoctrine-ormyii-chtml

add new item to CHtml in yii


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


Solution

  • 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