Last active
June 5, 2017 19:20
-
-
Save elton182/e26a90ad2ff4bd4df0c31eb4e974ada6 to your computer and use it in GitHub Desktop.
Validar Data no CakePHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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' | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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