CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller.

Hi all.

I have a problem i would like to solve and appreciate any help :)

here it goes:

In my application i have two models: Project and User.

What im trying to do is when a user creates a project, i want to increment a property of the user createdProjects+1.

So, what i did was in the ProjectController:




public function actionCreate()

{

   $modelProject = new Project;

   $modelUser = User::model()->findByPk(Yii::app()->user->id);

               //gets the model of the user Logged


   ...


   if ($modelProject->validate())

   {

      $modelUser->createdProjects = $modelUser->createdProjects + 1;

      $modelUser->save();

   }

   ...

}



An Exception is thrown:

"CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller."

in the line [color="#8B0000"]$modelUser->save()[/color] when i try to update the User counter.

What am i doing wrong?

Thank you for your time.

Any tips?

Some questions that comes to mind:

  • what are your validation rules…

  • do you need it at all…

  • if yes, did you define the captcha action…

Didnt understand ur questions at all…

i do the validation() before the save() to avoid rollbacks. First i validate all the models and then save all at once.

The error message say “CCaptchaValidator”… so you have “some” problem with this validator… what I asked you is if you have that validatior in your model validation rules or maybe it’s there by error… if you have it… than you need to have the action “captcha” defined in your controller… do you have it?

For an example… check the default code generated by Gii… the captcha validator is used in the model ContactForm and the "captcha" action is defined in the controller SiteController.

Did solve my problem :)

http://www.yiiframework.com/forum/index.php/topic/25860-save-not-working-after-loading-model/

Thank you for your time