我需要在JSON的帮助下验证Yii2中的开始日期是否小于结束日期

我需要在JSON的帮助下验证Yii2中的开始日期是否小于结束日期,json,date,yii2-advanced-app,Json,Date,Yii2 Advanced App,这些是显示日期的视图文件的图像。 此处日期未验证,它甚至在开始日期之前选择日期。 我还附上了编码截图,请看一下,让我找到合适的答案 我假设,您可以在模型中验证它是$courseTest 根据以下规则: public function rules() { return [ ['setting_test_attempt_time', function($attribute, $params) { $decoded = json_decode($this

这些是显示日期的视图文件的图像。 此处日期未验证,它甚至在开始日期之前选择日期。 我还附上了编码截图,请看一下,让我找到合适的答案


我假设,您可以在模型中验证它是
$courseTest
根据以下规则:

public function rules() {
    return [
        ['setting_test_attempt_time', function($attribute, $params) {
            $decoded = json_decode($this->$attribute, true);
            if ($decoded['from'] > $decoded['to']) {
                $this->addError($attribute, 'The From date must be less than To');
            }
        }]
    ];
}

你这样做是为了什么?我应该在这张图中看到什么:)与我们共享一些代码。