-
-
Save TiuTalk/2330623 to your computer and use it in GitHub Desktop.
Client Model
This file contains hidden or 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
<?php | |
class Client extends AppModel { | |
public $validate = array( | |
'responsavel'=> array( | |
array( | |
'rule' => 'maiorDeIdade', | |
'message' => 'Campo deve ser preenchido' | |
) | |
) | |
); | |
public function maiorDeIdade($data) { | |
$responsavel = array_shift($data); | |
$nascimento = $this->data[$this->alias]['nascimento']; // Pega o valor do campo "nascimento" | |
$ano_nascimento = date('Y', strtotime($nascimento)); // Ano de nascimento | |
$idade = date('Y') - $ano_nascimento; | |
// Maior de idade? | |
if ($idade >= 18) | |
return true; | |
// Tem um responsável | |
if (!empty($responsavel)) | |
return true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment