"Manual" CCaptcha validation of verification code

How can I "manually" validate a CCaptcha verification code?

I’m not using Active Record nor CActiveForm, not even a form. I pick the user-entered validation code and I send it through ajax to a model’s method as a parameter. Inside this method how can I check if the code is correct?

I’m trying with:


if( CCaptchaAction->validate($userInput) )

but this is obviously wrong ( "PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR" )

How should I do?

Check the CCaptchaValidator source code to see how it’s done - http://code.google.com/p/yii/source/browse/trunk/framework/validators/CCaptchaValidator.php

I’ve seen the code but I still can’t figure how to do it! :(

maybe I should instantiate the class and then call the method. would it be enough to do this?


$ca = new CCaptchaAction;

if( $ca->validate($userInput) ) { ...do something... }

The previous will not work. This is the right way to do it:


        $ca = Yii::app()->getController()->createAction('captcha');

        if (! $ca->validate($userInput, false) ) // false stands for 'case insensitive'

            return 'wrongcode';