Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@elton182
Last active June 5, 2017 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elton182/e26a90ad2ff4bd4df0c31eb4e974ada6 to your computer and use it in GitHub Desktop.
Save elton182/e26a90ad2ff4bd4df0c31eb4e974ada6 to your computer and use it in GitHub Desktop.
Validar Data no CakePHP
$validator
->add('occurrence_date', 'custom', [
'rule' => function ($value, $context) {
Log::write('debug',$value);
$dia = intval(substr($value, 0,2));
$mes = intval(substr($value, 3,2));
$ano = intval(substr($value, 6,4));
if(Chronos::createFromDate($ano, $mes, $dia)){
return true;
}
else
return false;
},
'message' => 'Data inválida'
]);
$validator
->add('occurrence_date', 'custom', [
'rule' => function ($value, $context) {
Log::write('debug',$value);
if(Chronos::createFromFormat('d/m/Y',$value)){
return true;
}
else
return false;
},
'message' => 'Data inválida'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment