Created
March 8, 2012 10:49
-
-
Save m4rcsch/2000376 to your computer and use it in GitHub Desktop.
isUnique Validator for Lithium (li3) PHP Framework
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('isUnique', function($data, $params, $options) { | |
$model = $options['model']; | |
$field = $options['field']; | |
$key = $model::meta('key'); | |
$entity = $model::first(array('conditions' => array($field => $data))); | |
$identifier = isset($options['values'][$key]) ? $options['values'][$key] : null; | |
if ($entity && $entity->data() && $identifier == (string) $entity->$key) { | |
return false; | |
} | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment