Yii Framework Forum: How to attach behaviors to yii built-in helpers (e.g., CHtml)? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to attach behaviors to yii built-in helpers (e.g., CHtml)? Rate Topic: -----

#1 User is offline   liang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-June 10

Posted 16 August 2010 - 04:50 PM

How to attach behaviors to yii built-in helpers (e.g., CHtml)? Or other ways to extend a helper without changing the name of that helper?

Thanks.
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 16 August 2010 - 05:29 PM

Unfortunately, that's not possible for now. The helpers are static and they don't extend from CComponent (which is a requirement in order to attach behaviors).

You may simply create a new class (Html) and extend it from CHtml.
0

#3 User is offline   liang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-June 10

Posted 16 August 2010 - 05:58 PM

View PostY!!, on 16 August 2010 - 05:29 PM, said:

Unfortunately, that's not possible for now. The helpers are static and they don't extend from CComponent (which is a requirement in order to attach behaviors).

You may simply create a new class (Html) and extend it from CHtml.


Thanks.
But some classes (e.g., CActiveForm) rely on CHtml, if I create a new class named Html, it makes no change on CActiveForm. Any good way to handle this? (Actually, I want to override some methods in CHtml like CHtml::activeCheckBoxList, which will in turn change CActiveForm::checkBoxList.)
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 16 August 2010 - 06:16 PM

I don't know of any way to handle this. Hopefully we will see another approach about helpers in future. For example so that you can define the html-helper you want to use via CActiveForm::$htmlHelper or something.
0

#5 User is offline   liang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-June 10

Posted 16 August 2010 - 06:34 PM

View PostY!!, on 16 August 2010 - 06:16 PM, said:

I don't know of any way to handle this. Hopefully we will see another approach about helpers in future. For example so that you can define the html-helper you want to use via CActiveForm::$htmlHelper or something.


Thanks! At this moment, my solution might be extending CActiveForm to ActiveForm, by replacing all "CHtml" with "Html" in CActiveForm.php and saving as ActiveForm.php
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users