Why does beforeValidate return boolean but afterValidate return void?

I’m writing a checkout process and I’m using beforeValidate and afterValidate to perform various functions. I noticed though that beforeValidate returns a boolean value that can be used to fail the validation, afterValidate however does not have this (at least not the base method). I’m wondering why this is?

You see I have some processes that I want performed after validation but if that process fails I want validation to fail. In this case it is payment processing, once I know the form data has validated I want to process the payment but if that fails I want validation to fail. Is there a better way to achieve what I need than using afterValidate?

You can use http://www.yiiframework.com/doc/api/1.1/CModel#addError-detail

e.g. in a model




function processPayment()

{

   if(!$success)

  { 

      $this->addError('payment', 'not successful'); //where payment is some place holder property for payment errors.

      return false;

  }

return true;

}



and somewhere in controller




if($model->validate() && $model->processPayment())

{

// show errors

}