简体   繁体   English

CakePHP - 保存日期字段时出错

[英]CakePHP - Error saving date field

I have trouble saving my date field into database using CakePHP. 我无法使用CakePHP将日期字段保存到数据库中。

Table column name 表列名称

[User].[dob]

View 视图

<?php echo $this->Form->input('dob', array('type'=> 'date', 'label' => FALSE, 'dateFormat' => 'DMY', 'minYear' => date('Y') - 111, 'maxYear' => date('Y'))); ?>

I get the following error when I submit the form - 提交表单时出现以下错误 -

2011-12-29 00:33:57 Debug: Notice (8): Array to string conversion in [C:\\xampp\\htdocs\\dearmemoir\\cake\\libs\\router.php, line 1573] 2011-12-29 00:33:57调试:注意事项(8):[C:\\ xampp \\ htdocs \\ dearmemoir \\ cake \\ libs \\ router.php,第1573行]中的数组到字符串转换

This field is part of the Auth User Model. 该字段是Auth用户模型的一部分。 Any ideas what might be going wrong? 什么想法可能会出错?

This line of code did the magic for me - 这行代码为我带来了魔力 -

$this->data['User']['dob'] = date('Y-m-d', strtotime($this->data['User']['dob']));

I am able to save data now! 我现在能够保存数据!

I suspect that you are looking in the wrong place. 我怀疑你在找错了地方。 The error message is coming from the CakePHP routing (router.php) - ie possibly the redirect URL that you are using. 错误消息来自CakePHP路由(router.php) - 即可能是您正在使用的重定向URL。

The example code you give looks correct, it almost exactly matches an example from the Cake cookbook : 您给出的示例代码看起来是正确的,它几乎完全匹配Cake cookbook中的示例:

echo $this->Form->input('birth_dt', array( 'label' => 'Date of birth', 'dateFormat' => 'DMY', 'minYear' => date('Y') - 70, 'maxYear' => date('Y') - 18 ));

You can add in a check for any validation errors . 您可以添加检查任何验证错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM