When I am trying to update a record in my database my site seems to lock up and I just get a spinning "processing" indicator. It seems to be when I am using the CUploadedFile stuff. Creation does not seem to cause any issues, just updating.
Has anybody seen this or have any ideas on what I am doing wrong here?
My controller update section looks like this:
public function actionUpdate($id)
{
if(!Yii::app()->user->checkAccess('ContactUpdate'))
{
throw new CHttpException(403,'You are not authorized to perform this action.');
}
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Contact']))
{
$model->attributes=$_POST['Contact'];
$file_image = CUploadedFile::getInstance($model,'image_name');
if ( (is_object($file_image) && get_class($file_image)==='CUploadedFile'))
$model->image_name = $file_image;
if($model->save())
{
if (is_object($file_image))
$model->image_name->saveAs(Yii::app()->basePath . '/../data/images/personnel/'.$model->image_name);
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('update',array(
'model'=>$model,
));
}
View (if it helps):
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'contact-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'image_name'); ?>
<?php
if ($model->image_name)
{
echo '<img height="150px" src="'.Yii::app()->baseUrl.'/data/images/personnel/'.$model->image_name.'"><br />';
echo 'Current file: '.$model->image_name.'<br />To use a different file, use the button below to select your new logo file. Files must be either JPG, GIF, or PNG formats.<br /><br />';
}
?>
<?php echo $form->fileField($model,'image_name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'image_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'notify_testimonial_submission'); ?>
<?php echo $form->dropDownList($model,'notify_testimonial_submission',$model->getNotifyTestimonialSubmissionOptions()); ?>
<?php echo $form->error($model,'notify_testimonial_submission'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'notify_service_class_request'); ?>
<?php echo $form->dropDownList($model,'notify_service_class_request',$model->getNotifyServiceClassRequestOptions()); ?>
<?php echo $form->error($model,'notify_service_class_request'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
My slimmed down model rules look like this:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('notify_service_class_request, notify_testimonial_submission', 'numerical', 'integerOnly'=>true),
array('image_name', 'length', 'max'=>255),
array('notify_service_class_request, notify_testimonial_submission', 'length', 'max'=>3),
array('image_name', 'unsafe'), // to allow for updates without new files specified
array('image_name', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true, 'wrongType'=>'Incorrect file format.'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, notify_service_class_request, notify_testimonial_submission', 'safe', 'on'=>'search'),
);
}