because it does not compare me 2 dates with cakephp comparison

0

This is the rule I have, but it does not work:

$validator
    ->add('end_date', 'comparison', [
          'rule' => ['comparison', 'end_date', '>', 'start_date']
          ])

I want to show that the final date is greater than the initial date

    
asked by Jorge 05.12.2017 в 20:33
source

1 answer

1

As I would do:

in the buildRules of the table would add the following rule, which calls a function that passes the two properties of the entity as a parameter.

$rules->add(function ($entity) {
        return $this->dateComparison($entity->end_date, $entity->start_date);
    }, 'dateComparison', [
        'errorField' => 'end_date',
        'message' => __('Is not greater than start date')
    ]);

Here is the function you would call:

public function dateComparison($startDate, $endDate)
{
    if($startDate > $endDate){
    return true;
    }

    return false;
}
    
answered by 13.12.2017 в 01:57