Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Forked from waltergalvao/Client Model
Created April 7, 2012 17:26
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 TiuTalk/2330623 to your computer and use it in GitHub Desktop.
Save TiuTalk/2330623 to your computer and use it in GitHub Desktop.
Client Model
<?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