Passing Validation Errors

Hi Everybody,

I’m new to yii and I’m not sure what I’m doing wrong.

I’m trying to create a file upload widget but I’m not sure how I’m meant to pass the errors back to the form.

I call my widget using the below code.

$this->widget('', array(

    'id' => $this->id,

    'controllerRoute' => '/admin/gallery',


The widget creates a form and on submit gets sent to the Image controller.

public function actionUpload()


        $model = new Image();

        $model->attributes = $_POST['Image'];

        $model->uploaded = date('Y-m-d H:i:s');




            $imageFile = CUploadedFile::getInstanceByName('Image[file]');

            $model->file_name = $imageFile->getName();





                // redirect to success page





//            $errors = $model->getErrors();

//            var_dump($errors);



But I’m not sure how to get back to my form with the errors.

I’m pretty sure I’m doing things in a roundabout way so any help is appreciated.


Are you using an ActiveForm? If so, have a look at

Otherwise, this might help you:

why you can not set on model rules function like



      array('image_name', 'file', 'allowEmpty' => TRUE,'types' => 'jpg, jpeg, gif, png','on'=>'update'),

Also you can check the hasError

 if (!$model->hasErrors()) {



     //set flash messge


Thanks for the replys, I had to rewrite a good bit of code to get it working. For some reason I was trying to use 2 controller for 1 action. But all is well now :)