Skip to content

Instantly share code, notes, and snippets.

@cebe
Created July 17, 2013 22:09
Show Gist options
  • Save cebe/6024994 to your computer and use it in GitHub Desktop.
Save cebe/6024994 to your computer and use it in GitHub Desktop.
Yii ActiveRecord Unique validator example
<?php
class Example extends CActiveRecord
{
// ...
public function rules()
{
return array(
array(
'username', 'unique', 'on'=>'register',
'allowEmpty' => false,
'attributeName' => 'username',
'caseSensitive'=> false,
'className'=>'Example',
'message'=>'Sorry, this username has already been taken.',
),
);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment