您可以在模型中尝试以下代码:
public function beforeSave($options = array()){
if(!empty($this->data)){
//pr($this->data);die;
$this->data['User']['Birthday'] = date('Y-m-d', strtotime($this->data['User']['Year'] . '-' . $this->data['User']['Month'] .'-' . $this->data['User']['Day']));
unset($this->data['User']['Year']);
unset($this->data['User']['Month']);
unset($this->data['User']['Day']);
}
return true;
}
您的表单中必须有以下表单字段:
<?php echo $this->Form->create('User', array('url' => $this->params));
echo $this->Form->input('Year', array('options' => $year_options, 'type' => 'select'));
echo $this->Form->input('Month', array('options' => $month_options, 'type' => 'select'));
echo $this->Form->input('Day', array('options' => $day_options, 'type' => 'select'));