Validate start date and end date in php (cakephp)

0

I'm doing a validator in the cakephp model so far I have:

public function validationDefault(Validator $validator){  
    $validator
        ->date('fechainicio')
        ->allowEmpty('fechainicio');

    $validator
        ->date('fechafin')
        ->allowEmpty('fechafin');



    return $validator;
}

I have the idea of doing a personalized validation so that the end date is greater than the start date, but I have no idea how to do ... any ideas?

EDITED

I was thinking of doing something like this:

 $validator
        ->date('fechafin')
        ->allowEmpty('fechafin')
        ->add(
            'cedula',
            ['validarFechas' => [
                'rule' => 'validarFechas',
                'provider' => 'table',
                'message' => 'Fecha final debe ser mayor a fecha de inicio',]
            ]);

With a function:

public function validarFechas($fechainicio,$fechafin) {
   $fechainicio=('fechainicio');
   $fechafin=('fechafin');
   if(strtotime($fechafin) > strtotime($fechainicio)){
       $v=true;
   }
   else{
       $v=false;
   }      
   return $v;
}

But it does not work ... any ideas ??

    
asked by Jassita V. Ocando 05.12.2018 в 21:37
source

0 answers