我有一个像这样的数组:
$holiday = array(array('h_date' => $new_year, 'd_name' => 'New Year'),
array('h_date' => $memorial_day, 'd_name' => 'Memorial Day')
foreach($holiday as $holidays){
$date = $holidays["h_date"];
$name = $holidays["d_name"]
当我保存在 mysql 数据库中时
$model = new Holiday();
$model->holiday_date = $date;
$model->display_name = $name;
$model->save();
当我写
$model->save(false);
值已成功保存但没有“假”数据
在看到验证错误时未保存而不是错误:
Array ( [holiday_date] => Array ( [0] => The format of Holiday Date is invalid.))
我们用
protected function beforeSave(){
if(parent::beforeSave()){
$this->holiday_date=date('Y-m-d',strtotime($this->holiday_date));
return TRUE;
}
return false;
}