Kohana 3: Callback validation
NOTE: This question refers to Kohana 3.0 only. Kohana 3.1 and newer handle validation callbacks in a completely different way.
I'm doing a validation with a callback (ORM). These are my code:
class Model_Loja extends ORM {
// more code goes here!
protected $_callbacks = array(
'endereco' => array('endereco_unico')
);
public function endereco_unico(Validate $validate, $campo) {
$resultado = $this->where('endereco', '=', $this->endereco)-开发者_Python百科>find_all();
if(count($resultado)) {
return false;
}
else {
return true;
}
}
// more code goes here!
It's returning true or false (if there is a value, returns false) but how could i send a validation message when it returns false?
The following validation function sets an error for the field if validation fails:
public function endereco_unico(Validate $validate, $campo) {
if(count($this->where('endereco', '=', $this->endereco)->find_all())) {
$validate->error($campo, 'endereco_unico');
}
}
(Moved from question)
精彩评论