簡體   English   中英

如何在Yii框架中將date的默認值更改為null?

[英]How can I change the default value of date to null in Yii framework?

我是否需要對以下代碼進行任何更改才能將DATE的默認值設置為NULL? 我已經在數據庫中嘗試過,在那里將約束默認值更改為null,但是沒有找到任何解決方案。 你能給我個解決辦法嗎?

<?php 
        // $model->confirmation_dt ='03/03/2011';  // default date
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
        'model' => $model,
        'attribute' => "confirmation_dt",
        'options'   => array(
            'dateFormat' => Yii::app()->params['dateFmtDP'],
            'yearRange'  => '1900:c+10',
            'changeYear' => true
        ),
        'htmlOptions' => array(
            'size' => '10',         // textField size
            'maxlength' => '10',    // textField maxlength
            // 'value' => '03/03/2011', // Alternate method for default date
            // 'value' => date('d/m/Y'), // set the default date as today's date
            // 'value' => NUll, // set the default date here // This one is not working
        ),
    )); ?>

提前致謝!

表單提交中的所有數據都可以作為字符串(或字符串數​​組)使用。 因此,空字段由空字符串表示。 如果要將其更改為null ,則應使用default驗證器,它將空字段更改為指定值:

public function rules() {
    return [
        // ...
        ['confirmation_dt', 'default', 'value' => null],
    ];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM