title: Is it Yii or is it me who is wrong?
body: <p>Hi there I have written a code that ietrates through whole array and copies the images to a folder and inserts data in record. Now funny thing is that <code>$model-&gt;save()</code>does not show error it returns true. and program never goes into else</p>
  
  <p>now what happens loop continues to run and completes its ietration without breaking. I can not guess who is wrong. greater chances are me as i am most of time :)</p>
  
  <p>here is code</p>
  
  <pre><code>   protected function saveImage($formData,$model)
          {                   
                 if ($formData === null)
                     return;                   
                  $idx=0;
  
              foreach($formData['title'] as $image)
              {
                  $model-&gt;title = $image;                    
                  $file= dirname(Yii::app()-&gt;request-&gt;scriptFile) . DIRECTORY_SEPARATOR 
                          . DIRECTORY_SEPARATOR .'images\hotelImages'. DIRECTORY_SEPARATOR 
                          . $model-&gt;hotel-&gt;name;
  
                  $model-&gt;image = Yii::app()-&gt;baseUrl. "/images/hotelImages/".$_FILES['HotelImages']['name'][$idx];//image path
  
                  if($model-&gt;save())
                  { 
                      echo $idx.'&lt;br /&gt; it was sucess&lt;br /&gt;';
  
                      If(file_exists($file)) 
                      {
                          copy($_FILES['HotelImages']['tmp_name'][$idx],$file."/".$_FILES['HotelImages']['name'][$idx]);
                      }
                      else
                      {
                           mkdir($file); 
                          copy($_FILES['HotelImages']['tmp_name'][$idx],$file."/".$_FILES['HotelImages']['name'][$idx]);
                      }
                      $idx++;
  
                  }//if there was error
                   else
                   {
                       print_r($model-&gt;getErrors());
                       yii::app()-&gt;end();                
                      return FALSE;
                   }
                   echo '&lt;br /&gt;end reached &lt;br /&gt;';
  
  
              }
               yii::app()-&gt;end(); 
               return true;
          }
  </code></pre>
  
  <p>var_dump for $formdata is </p>
  
  <pre><code>array
  (
      'title' =&gt; array
      (
          '0' =&gt; 'title1'
          '1' =&gt; 'title2'
      )
  )
  </code></pre>
  
  <p><strong>No mater what ever the ietration count for foreach loop database gets only single row</strong></p>