php - How to have multiple fields (D/M/Y) for single date property in Yii? -


i want take user birth day database , there field in table called dob. when created model , crud generated text field dob always. want create 3 inputs.

  1. for years
  2. for months
  3. and dates

so question how add inputs in model's form. thinking of adding new attributes model class there no such attributes in table.

add fields model:

public $year; public $month; public $date; 

add these methods model:

protected function afterfind() {     parent::afterfind();      $dob = explode('/', $this->dob);     $this->year = $dob[0];     $this->month = $dob[1];     $this->date = $dob[2];      return $this; }  protected function beforesave() {     parent::beforesave();      $this->dob = $this->year .'/'. $this->month .'/'. $this->date;      return $this; } 

you can use them in cactiveform form:

<?php echo $form->textfield($model, 'year'); ?> <?php echo $form->textfield($model, 'month'); ?> <?php echo $form->textfield($model, 'date'); ?> 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -