<bdo id='kqWrI'></bdo><ul id='kqWrI'></ul>
<legend id='kqWrI'><style id='kqWrI'><dir id='kqWrI'><q id='kqWrI'></q></dir></style></legend>

    <i id='kqWrI'><tr id='kqWrI'><dt id='kqWrI'><q id='kqWrI'><span id='kqWrI'><b id='kqWrI'><form id='kqWrI'><ins id='kqWrI'></ins><ul id='kqWrI'></ul><sub id='kqWrI'></sub></form><legend id='kqWrI'></legend><bdo id='kqWrI'><pre id='kqWrI'><center id='kqWrI'></center></pre></bdo></b><th id='kqWrI'></th></span></q></dt></tr></i><div id='kqWrI'><tfoot id='kqWrI'></tfoot><dl id='kqWrI'><fieldset id='kqWrI'></fieldset></dl></div>

      <tfoot id='kqWrI'></tfoot>
    1. <small id='kqWrI'></small><noframes id='kqWrI'>

    2. 如何在 Yii 中将日期设置为 NULL?

      How can I set a date to NULL in Yii?(如何在 Yii 中将日期设置为 NULL?)
      <legend id='ZjBQ5'><style id='ZjBQ5'><dir id='ZjBQ5'><q id='ZjBQ5'></q></dir></style></legend>
        <tbody id='ZjBQ5'></tbody>

            <tfoot id='ZjBQ5'></tfoot>

            <small id='ZjBQ5'></small><noframes id='ZjBQ5'>

              <bdo id='ZjBQ5'></bdo><ul id='ZjBQ5'></ul>
              <i id='ZjBQ5'><tr id='ZjBQ5'><dt id='ZjBQ5'><q id='ZjBQ5'><span id='ZjBQ5'><b id='ZjBQ5'><form id='ZjBQ5'><ins id='ZjBQ5'></ins><ul id='ZjBQ5'></ul><sub id='ZjBQ5'></sub></form><legend id='ZjBQ5'></legend><bdo id='ZjBQ5'><pre id='ZjBQ5'><center id='ZjBQ5'></center></pre></bdo></b><th id='ZjBQ5'></th></span></q></dt></tr></i><div id='ZjBQ5'><tfoot id='ZjBQ5'></tfoot><dl id='ZjBQ5'><fieldset id='ZjBQ5'></fieldset></dl></div>

              1. 本文介绍了如何在 Yii 中将日期设置为 NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个日期列,通常将值设为 dd.MM.yyyy.它在模型的 rules() 中的验证规则是这样的:

                I have a date column that usually takes values as dd.MM.yyyy. Its validation rule in the model's rules() is this:

                array('start, end', 'date', 'format' => 'dd.MM.yyyy'),
                

                我正在从 CSV 文件填充数据库,如果 CSV 记录为空,我希望能够将日期设置为 NULL(即没有).所以,我正在做:

                I'm populating the database from a CSV file, and I'd like to be able to set the date to NULL (i.e. nothing) if the CSV record is empty. So, I'm doing:

                if (empty($csv_data)) {
                  $user->start = new CDbExpression('NULL');
                } else {
                  $user->start = $csv_data;
                }
                

                但我收到一个错误,指出日期格式无效.这是为什么?

                But I get an error that the date format is invalid. Why is that?

                CDateValidator 文档 说allowEmpty 属性默认为 true,所以应该可以设置为 NULL 吧?请注意,如果我只是将 "" 字符串分配给日期,它会将其转换为 0000-00-00 00:00:00 时间戳,这不是NULL.

                The CDateValidator documentation says that the allowEmpty property is true by default, so it should be able to set this to NULL, right? Note that if I just assing the "" string to the date, it'll convert it to a 0000-00-00 00:00:00 timestamp, which is not NULL.

                推荐答案

                in model rules():

                in model rules():

                array('start, end', 'date', 'format' => 'dd.MM.yyyy'),
                array('start, end', 'default', 'setOnEmpty' => true, 'value' => null),
                

                还有,

                if (empty($csv_data)) {
                  $user->start = null;
                } ...
                

                也应该这样做.

                这篇关于如何在 Yii 中将日期设置为 NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tbody id='TCw7R'></tbody>
                1. <tfoot id='TCw7R'></tfoot>

                    <legend id='TCw7R'><style id='TCw7R'><dir id='TCw7R'><q id='TCw7R'></q></dir></style></legend>
                    • <i id='TCw7R'><tr id='TCw7R'><dt id='TCw7R'><q id='TCw7R'><span id='TCw7R'><b id='TCw7R'><form id='TCw7R'><ins id='TCw7R'></ins><ul id='TCw7R'></ul><sub id='TCw7R'></sub></form><legend id='TCw7R'></legend><bdo id='TCw7R'><pre id='TCw7R'><center id='TCw7R'></center></pre></bdo></b><th id='TCw7R'></th></span></q></dt></tr></i><div id='TCw7R'><tfoot id='TCw7R'></tfoot><dl id='TCw7R'><fieldset id='TCw7R'></fieldset></dl></div>

                        • <bdo id='TCw7R'></bdo><ul id='TCw7R'></ul>

                          <small id='TCw7R'></small><noframes id='TCw7R'>