Yii 1.1: activedateselect

Combines ehtmldataselect and activedatelist
6 followers

This extention simplifies creation of three dropDownLists for collecting dates on models. Combines ehtmldataselect (manipulates dates under 1970-01-01) and activedatelist (adds behavour for onBeforeValidate).

Requirements

works fine on Yii 1.1.7 or above

Installation

Extract the release file under protected/extensions

Usage

in view:

$this->widget('ext.ActiveDateSelect',
    array(
      'model'=>$model,
      'attribute'=>'birthdate',
      'reverse_years'=>true,
      'field_order'=>'DMY',
      'start_year'=>1910,
      'end_year'=>date("Y",time()),
    )
);

in controller:

$model=new User;
if(isset($_POST['User'])){
   $model->attributes=$_POST['User'];
   ActiveDateSelect::sanitize($model, 'birthdate');
   if($model->validate()){
       $model->save();
       ...
   }
}

Don't forget to import the class to your controller or to add the extention directory to your main config.

Total 1 comment

#9189 report it
Ahyo Haryanto at 2012/07/27 12:23am
Great

but you should import before use in controller

$model=new User;
if(isset($_POST['User'])){
   $model->attributes=$_POST['User'];
   Yii::import('ext.ActiveDateSelect'); // add this line**
   ActiveDateSelect::sanitize($model, 'birthdate');
   if($model->validate()){
       $model->save();
       ...
   }
}

Leave a comment

Please to leave your comment.

Create extension