Unable to use CUniqueValidator (without using rules())

I’ve been trying to add a custom validation, but it keeps throwing the error below.

This is the code I’m using inside the actionCreate() of my Controller.

$uniqueValidator = new CUniqueValidator;

$uniqueValidator->attributeName = 'phone_mobile';

$uniqueValidator->validate($model, array('phone'));

Now, I know that the same thing can be achieved using the code below in rules(),

array('phone', 'unique', 'attributeName'=>'phone_mobile'),

It works smoothly if I do it using rules(). How to do it without using rules()? What is the correct methods to use these validator classes explicitly?

The argument should be a string, not an array AFAIK. :)

[color=#000000]$uniqueValidator[/color][color=#666600]->[/color][color=#000000]validate[/color][color=#666600]([/color][color=#000000]$model[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]‘phone’[/color][color=#666600]);[/color]

Okay. I’ll try that. I just went with what was written here.


Thanks for sharing !!!