Flex DateField 和 MySQL 默认日期值 0000-00-00
我创建了一个服务和 callResponder(通过 Flash Builder 4 中的生成服务调用和生成表单)来查询 MySQL 数据库以获取姓名和出生日期。
我想我的问题很简单,但我一直无法找到解决方案...
当我在 MySQL 中有一个空日期(0000-00-00)时,我绑定的 DateField 指示 1899-11-30
我尝试了几乎所有方法可能...自定义 labelFunction,在调用我的服务后直接调用的自定义函数,以尝试像这样处理我的数据..:
protected function parseDate(date:Date):void
{
if (date.getFullYear() == -1) {
friendbirthdate.selectedDate = null;
} else {
var df:DateFormatter = new DateFormatter;
df.formatString = 'YYYY-MM-DD';
friendbirthdate.selectedDate = date;
}
}
不幸的是,这仅部分有效。当我尝试更新数据库中的相同表单时,我断开了连接。我在这里遗漏了一些东西,非常感谢您提供一两个提示:-)
谢谢!
I created a service and callResponder (Via Generate Service Call and Generate Form in Flash Builder 4) that query a MySQL database for a name and a birth date.
My problem is so simple I guess but I haven't been able to find the solution...
When I have an empty date in MySQL (0000-00-00), my binded DateField indicates 1899-11-30
I tried almost everything possible... A custom labelFunction, a custom function called straight after the call to my service to try to handle my data like this.. :
protected function parseDate(date:Date):void
{
if (date.getFullYear() == -1) {
friendbirthdate.selectedDate = null;
} else {
var df:DateFormatter = new DateFormatter;
df.formatString = 'YYYY-MM-DD';
friendbirthdate.selectedDate = date;
}
}
Unfortunately, this works only partially. When I try to update this same form in the database I get disconnected. I'm missing something here and would greatly appreciate a tip or two :-)
THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您为未知日期存储 NULL,而不是“0000-00-00”。在这种情况下,NULL 是更准确的值。
如果您想将其存储为 NULL 并将其显示为不同的值,您可以执行以下操作:
I recommend that you store NULL for unknown dates, as opposed to '0000-00-00'. NULL is a more accurate value in this case.
If you want to store it as NULL and display it as a different value you can do something like this:
不知道它是否会对某人有帮助,但我无法从包含日期字段的表单中插入值。该表单是通过 Flash Builder 生成表单工具生成的。
问题在于,无论如何,Flash Builder 生成的服务都需要一个 Date 对象...如果您提交表单而没有在 DateField 中选择日期,则服务调用将崩溃。
让我们看一下生成的示例服务的一部分(创建和更新函数),我们可以看到 PHP 期望将日期对象转换为字符串,如下所示:
首先,确保 MySQL 中的日期字段具有作为 NULL 默认值。
然后更改创建和更新函数,如下所示:
这样,服务调用脚本就不会尝试执行 null->toString('...') 操作
Don't know if it will help somebody but I had trouble to insert values from a form, containing a DateField. That Form has been generated through the Flash Builder Generate Form tool.
The problem is that the service generated by Flash Builder expect a Date Object, no matter what... If you submit the form without selecting a date in the DateField, the service call crashes.
Let's have a look at a part of the generated sample service (Create and Update functions), we can see that PHP is expecting to transform a Date Object to a String like this :
First of all, be sure that your Date field in MySQL has as NULL default value.
Then alter the create and update functions like this :
This way, the service call script won't try to do kinda null->toString('...')