Last active
December 13, 2015 16:59
-
-
Save mbischof/4944180 to your computer and use it in GitHub Desktop.
CMaskedTextField, ActiveRecord::afterFind(), ActiveRecord::beforeSave()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$this->widget('CMaskedTextField', array( | |
'model' => $model, | |
'attribute' => 'birthday', | |
'mask' => '99.99.9999', | |
'htmlOptions' => array('size' => 32) | |
)); | |
public function beforeSave() | |
{ | |
if (!empty($this->birthday)) { | |
list($day, $month, $year) = explode('.', $this->birthday); | |
$this->birthday = implode('-', array($year, $month, $day)); | |
} else { | |
$this->birthday = '0000-00-00'; | |
} | |
return parent::beforeSave(); | |
} | |
public function afterFind() | |
{ | |
list($year, $month, $day) = explode('-', $this->birthday); | |
$this->birthday = implode('.', array($day, $month, $year)); | |
parent::afterFind(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment