[[+content_image]]
M
M
Michael2018-04-14 11:04:56
Yii
Michael, 2018-04-14 11:04:56

How to properly validate date-local in yii2?

Good afternoon, there was such a question, how to correctly implement date-local validation in yii2?

public function rules()
    {
        return [
            [['date_notification'], 'date', 'format' => 'php:Y-m-d\TH:m'],
            [['date_add'], 'safe'],
        ];
    }

Accordingly, if data (null or empty) is not sent, it simply falls with an Exception.
I have a form on the page with two models, so I save anyway.
The problem is that even if it comes empty, it passes validation. In the format that I wrote above

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry Kim, 2018-04-15
@mix_gorbachev

Didn't understand anything from the description. If you want to get an intelligible answer, learn how to compose the right question.
The date format is incorrect:
(most likely it should be 'php:Y-m-d\TH:i')
If you want the data not to be empty - add:
add a default value:
Perhaps it falls with an Exception for empty data, because the database does not provide a default value for the field date_notificationand is set to NOT NULL.
So call your grandmother.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question