我正在尝试将数据保存在表格中,但是当我保存它时会引发以下错误:
SQLSTATE [22007]:日期时间格式无效:1292 日期时间值不正确:第 1 行的列“date_updated”的“1540564519”保存模型评估补救措施
evaluation_remedy 表架构:
--
-- Table structure for table `evaluation_remedy`
--
CREATE TABLE IF NOT EXISTS `evaluation_remedy` (
`id` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`diet` text NOT NULL,
`is_local_food_store` tinyint(4) NOT NULL DEFAULT '0',
`product_image` varchar(255) DEFAULT NULL,
`product_description` text,
`product_url` varchar(255) DEFAULT NULL,
`importance` tinyint(4) NOT NULL DEFAULT '0',
`is_active` tinyint(4) NOT NULL DEFAULT '1',
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8;
--
-- Indexes for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
MODIFY `id` int(10) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=64;
让我知道是否需要任何其他信息。我很乐意分享解决方案所需的任何内容。
存储/保存功能:
public function saveEvaluationRemedyAction(){
// Instantiate new form for Evaluation Symptom Model
$form = new EbEvaluationRemedyForm();
if( $form ->isValid($this->request->getPost())){
// Get the Evaluation Symptom id (if any)
$id = $this->request->get( 'id', null );
// Get existing Evaluation Symptom (if any) or create a new one
if( null !== $id && $id !== '' ){
$evaluationRemedy = CxEbEvaluationRemedy::findFirst( $id );
} else {
$evaluationRemedy = new CxEbEvaluationRemedy();
}
// Bind form with post data
$form->bind( $this->request->getPost(), $evaluationRemedy );
// Save the form with new data
$evaluationRemedy->save();
// Saving linked remedies in Related Remedy Table
$remedies = $this->request->get('remedies_list');
if($remedies){
foreach ($remedies as $key => $remedy) {
$relatedRemedy = CxEbEvaluationRemedy::getIdByName($remedy);
$remedyObject = new CxEbEvaluationRemedyRelated();
$remedyObject->setEvaluationRemedyId($evaluationRemedy->getId());
$remedyObject->setEvaluationRelatedRemedyId($relatedRemedy['id']);
$remedyObject->save();
}
}
} else {
// Send error Json response
return CxHelper::SendJsonError($form->getHtmlFormattedErrors());
}
// Return success
return array( 'data' => 'Success' );
}
让我知道是否需要任何其他信息。我很乐意分享解决方案所需的任何内容。
谢谢