CJuiDatePicker/CActiveForm Yii Framework


CJuiDatePicker Example
CJuiDatePicker Example


For many of our web applications, we utilize the Yii Framework extensively.  A great feature of the framework is the CActiveForm, which allows you to link up your Model to your View in a very easy manner.  (See Model-View-Controller Architecture on Wikipedia for a good explanation of this concept.)

If you also use the Yii Framework, you might find yourself in a dilemma that we recently experienced.  We had a date field on our form, and wanted to use the CJuiDatePicker widget so that users get a nifty dropdown where they can select a date.  We also wanted to link it to the model, defaulting it to the field in our database if there was already an instance of the object.  Most Yii widgets only need you to link up with the ‘model’ option, but CJuiDatePicker is different.  To default the value, the ‘value’ line below must be used.

$this->widget('zii.widgets.jui.CJuiDatePicker', array(
  // additional javascript options for the date picker plugin

Do you know of other ways to accomplish this? Let us know in the comments!

Share this page:
  • Facebook
  • Twitter
  • Reddit
  • Google Bookmarks
  • email
  • Print
  • RSS
  • Digg
  • StumbleUpon
  • del.icio.us
  • Slashdot
  • Technorati
  • Tumblr

Steven Michaels

Steven Michaels specializes in PHP web applications utilizing MediaWiki, WordPress, Yii Framework and others. He is an open source contributor and leads development for both of Hollow Developers' internal projects, HollowGame and SpeechEase.

Facebook comments:

Leave a Reply