Skip to content

Commit

Permalink
Fixing the custom rules example in security.validation, finally...
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Aug 16, 2010
1 parent 0db79c5 commit 6d90568
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions guide/security.validation.md
Expand Up @@ -105,11 +105,13 @@ Note that all array parameters must still be wrapped in an array! Without the wr

Any custom rules can be added using a [PHP callback](http://php.net/manual/language.pseudo-types.php#language.types.callback]:

$post->rule('username', array($model, 'unique_username'));
$post->rule('username', 'User_Model::unique_username');

[!!] Currently (v3.0.7) it is not possible to use an object for a rule, only static methods and functions.

The method `$model->unique_username()` would be defined similar to:

public function unique_username($username)
public static function unique_username($username)
{
// Check if the username already exists in the database
return ! DB::select(array(DB::expr('COUNT(username)'), 'total'))
Expand Down

0 comments on commit 6d90568

Please sign in to comment.