I would like to store 3 input fields in 1 mysql database field, named ‘date’. In stead of storing a date in the yyyy-mm-dd format, it only stores the word ‘array’… Can anybody help?
the $page->attributes store all the post form and arese all the previus data. Also check if the implode("-", $_POST[‘Page’][‘date’]) has the data that you want, by using echo
<?php
class User extends CActiveRecord
{
// In DB we only have "dateofbirth" as DATE column.
// We add some extra columns here:
public $day;
public $month;
public $year;
/**
* Prepare day/month/year for birthday dropdown
*/
public function afterFind()
{
$ts = strtotime($this->dateofbirth);
list($this->day,$this->month,$this->year) = array(date('j',$ts), date('n',$ts), date('Y',$ts));
}
/**
* Convert day/month/year back to a date string for dateofbirth
*/
public function beforeSave()
{
// Create timestamp of entered date
$ts = strtotime(sprintf('%s-%s-%s',$this->year,$this->month,$this->day));
$this->dateofbirth = date('d.m.Y',$ts);
}
}
EDIT: Don’t forget to add rules for “day”, “month” and “year”.