validate() return values for model - array

Hi,

I like your book, but I have a question about returning error messages from an model[]

On site 96 you show following example




public function actionIndex()

{

      $models = array();

      if(!empty($_POST['Task']))

      {

            foreach($_POST['Task'] as $taskData)

            {

                  $model = new Task();

                  $model->setAttributes($taskData);


                  if($model->validate())

                      $models[] = $model;

            }

       }

}



What is happening here?




                  if($model->validate())

                      $models[] = $model;



Example:

I’ve added 4 Tasks on my view file and the third input field fails, because the user don’t input a title.

How can I show the error-Message for field 3?

How does I now that field 3 returns an error?

thx

At that line we’re just adding a model object to an array. Nothing more.

So overall we’re iterating over all data from POST. For each data set we’re creating model and filling it with the data. Then trying to validate it. If it fails, model will not be added to models array. As for the error itself, you can get these after validating like $model->getErrors().