Difference between #1 and #2 of
Create your own Validation Rule

Revision #2 has been created by nickcv on Mar 31, 2011, 9:41:23 AM with the memo:

made correction to headers
« previous (#1) next (#3) »


Title unchanged

Create your own Validation Rule

Category unchanged


Yii version unchanged

Tags unchanged

validator, validation rules, model validation, create validator

Content changed

Some times the core validation rules provided by Yii won't satisfy all your needs, so you'll need to create your very own validation rule. ##Easy approach: inside-model rule

The easiest way to create a new validation rule is inside the model that is going to use it.
Add Error accepts two parameters: the first one is the name of the attribute that you want to display the error in your form, the second one is the actual error string you want to be displayed.

##Complete approach: extending the CValidator class

If you need your custom validation rule in more then one model the best thing to do is extending the CValidator class.
Extending this class you also can take advantage of other features, like [CActiveForm::$enableClientValidation](http://www.yiiframework.com/doc/api/1.1/CActiveForm#enableClientValidation-detail), first implemented with Yii 1.1.7 release.

##Creating the class file
58 0
Viewed: 212 543 times
Version: 1.1
Category: How-tos
Written by: nickcv
Last updated by: Gismo
Created on: Mar 31, 2011
Last updated: 5 years ago
Update Article


View all history