HOW to Send Custom Errors

Hi, I need to send errors to the user, an those errors are more like "business" or Logic errors.

I created a Cform based class, and interact with the user, everything works fine, with error based on "rules".

But I need some other errors:

like :

"The period (year and month) you select is allready taken…"

or

"Please especify one range condition"

I mean there are some logic errors.

What Objetc::method should be executed from the controller ?


public function actionGenerate() {


		$model = new GeneraCuotaForm;

		

		$anios = CuotaDefAnual::model()->getAniosActivos();

		/*

		*/

		

		//$anios = $anios	;	

		

		if (isset($_POST['GeneraCuotaForm'])) {

			//echo print_r($_POST['GeneraCuotaForm']['anio']);

			//echo print_r($_POST['GeneraCuotaForm']);

			$model->setAttributes($_POST['GeneraCuotaForm']);

                        //*** Validations ***     


			/*if ($model->save()) {

				if (Yii::app()->getRequest()->getIsAjaxRequest())

					Yii::app()->end();

				else

					$this->redirect(array('view', 'id' => $model->id));

			}*/

		}


		$this->render('generacuota', array( 'model' => $model, 'anios' => $anios));

	

	}



I couldn’t find any answer on tutorials.

Best Regards

/* Moved from Tips, Snippets & Tutorial to General Discussion */

You can create custom validators like the authenticate validator in this section of the guide. Also, you can specify your own message to the predefined validators by using the message attribute in rules.

/Tommy

Tommy, I found this solution, tell me if I’m using BAD preactices:

I just add an error, but with an unexistent Attribute:




			$model->addError('dummy','Error General');

			Yii::app()->user->setFlash('error','Error General');




I haven’t any property “dummy”, but the error shows with $model->errorSummary()

So what’s I need,

Anyway, setFlash doesn’t work for me … :(

Best Regards