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('ext.gallery.UploadManager', 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');
var_dump($model->validate());
if($model->validate())
{
$imageFile = CUploadedFile::getInstanceByName('Image[file]');
$model->file_name = $imageFile->getName();
$model->save();
if($model->save())
{
$imageFile->saveAs('gallery/'.$model->file_name);
// redirect to success page
}
}
else
{
// $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.
Thanks