【发布时间】:2015-08-12 08:55:34
【问题描述】:
我正在尝试使用 FormHelper 输入将 null 插入到我的数据库中。
选项应该是:
<?= $this->Form->input('preferedtimeformat', [
'label' => __('prefered representation of date and time'),
'options' => [
NULL => __('standard of your locale'),
'yyyy-MM-ddThh:mm:ss.sTZD' => __('ISO 8601 (yyyy-MM-ddThh:mm:ss.sTZD)'),
'eee, dd MMM yyyy hh:mm:ss xx' => __('RFC 2822 (eee, dd MMM yyyy hh:mm:ss xx)'),
'h:m:s d.M.yyyy' => __('german style (h:m:s d.M.yyyy)'),
'd.M.yyyy h:m:s' => __('invers german style (d.M.yyyy h:m:s)')
...some more options...
]
]) ?>
这应该有助于用户在需要或需要时指定另一个日期时间格式。 Time::i18nFormat() 接受 null 作为 Datetimeformat,然后使用您为其提供的语言环境的预设。
但是从表单中使用 NULL 选项创建用户不起作用,所以我将一个空字符串 ant not null 保存到数据库中。
有没有比在控制器中检查空字符串并将其替换为 NULL 更好的解决方案?
【问题讨论】:
标签: forms cakephp internationalization cakephp-3.0