Last active
December 16, 2015 02:29
-
-
Save palibaya/5362798 to your computer and use it in GitHub Desktop.
Composite Unique
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
<?php | |
class MyModel extends CActiveRecord | |
{ | |
public function rules() | |
{ | |
return array( | |
array('attr_a', 'compositeUnique', 'other' => 'attr_b'), | |
); | |
} | |
public function compositeUnique($attribute,$params) | |
{ | |
$object = $this->model()->findByAttributes(array( | |
$attribute => $this->{$attribute}, | |
$params['other'] => $this->{$params['other']}, | |
)); | |
if ($object !== null) { | |
$this->addError($attribute, 'Ur bla..bla.. is not unique!'); | |
} | |
} | |
} | |
Hahaha.. padahal belum di ujicoba
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wah mantep sekale gan... Suksesssss...hehe
Thanks bgt gan