I am trying to build a form which would upload an image to the server. So I have 3 files.
Model Upload.php
<?php
class Upload extends CActiveForm
{
public $image;
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}
}
View Upload.php
<div class="box">
<div class="body">
<header class="clearfix">
<div class="icons"><i class="icon-picture"></i></div>
<h5 class="pull-left">Upload Your Memes</h5>
</header>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm'); ?>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->label($model,'image'); ?>
<?php echo $form->fileField($model,'image') ?><br>
<?php echo CHtml::submitButton('Submit'); ?>
<?php $this->endWidget(); ?>
</div>
</div>
</div>
Controller.php
<?php
class MemeController extends AdminController {
public function actionUpload() {
$model=new Upload();
if(isset($_POST['image']))
{
$model->attributes=$_POST['image'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
{
$model->image->saveAs('/volume1/web/memes/templates/test.png');
$this->redirect(Yii::app()->request->urlReferrer);
}
}
$this->render('upload', array('model'=>$model));
}
}
Any ideas on why I am getting Error 500 MemeUpload and its behaviors do not have a method or closure named "getErrors". ? I have tried suggestions in this link however that doesn't really help. All I'm getting after those changes is another error which is: Upload Your Memes
Fatal error: Call to a member function errorSummary() on a non-object in /volume1/web/website/protected/modules/admin/themes/admin/views/meme/upload.php on line 10
where line 10 is <?php echo $form->errorSummary($model); ?>
Any ideas what else can I try?
Not tested, but I think you should have error filed below your file field as echo $form->fileField($model,'image');
echo $form->error($model,'image');
Resolved the issue for now. I just used standard HTML form tags rather than using the ones that Yii provide. This kind of fixed all of the errors that I had.