Skip to content

Instantly share code, notes, and snippets.

@mbischof
Last active December 13, 2015 16:59
Show Gist options
  • Save mbischof/4944180 to your computer and use it in GitHub Desktop.
Save mbischof/4944180 to your computer and use it in GitHub Desktop.
CMaskedTextField, ActiveRecord::afterFind(), ActiveRecord::beforeSave()
<?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