Yii Framework Forum: Own CHtml Methods? - Yii Framework Forum

Jump to content

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

Own CHtml Methods? best practise for implementing own CHTML'ish methods Rate Topic: -----

#1 User is offline   as_lh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 05-January 10

Posted 08 February 2010 - 06:37 AM


i am using quite a lot of very small methods in my views that repeat themselfes in other views as well.
i.e. presenting the amount of stars for a hotel or formating a number to become a price and so on.
So it would be nice to put them somewhere.
Having a widget, just for presenting a price seems a bit overdoing to me.

The best would be if i could write my own CHtml methods i guess so i could use/access them easily.

What do you think would be the best way to do that?

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 08 February 2010 - 07:10 AM

I don't think extending CHtml is a good idea in this case. Why not just create a helper class with only static methods, so you can access them: MyHelperClass::stars(5)? You can put your helpers in protected/helpers directory (and don't forget to set in config: 'import' => array('application.helpers.*', ...);

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