I have created a form with some entities (say name,address,etc.). And I have defined validation rules in model class. Client side validation is working perfectly as desired. Now I need to create custom validation rules. For that,in reference with http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/#hh0 , I have created a method called valid_number() in my model, and defined a simple null checking (I know there are built in rules for validating null,email,password, etc.. Here I have demonstrated a simple method of validation, actually I'm planning to do some custom validations). Please refer the code below. And please let me know what I am doing wrong.
//model
class Employee extends CActiveRecord{
public $number;
public function rules(){
return array(
array('number','valid_number'),
);
}
public function valid_number($attribute,$params){
if($this->$attribute == '' ){
CModel::addError($attribute, 'Number is null');
}
}
//view
</fieldset>
<?php echo $form->textFieldRow($model, 'number'); ?>
</fieldset>
var_dump($this->$attribute)output?