2
控制器上傳文件中的記錄:更新不改變警予
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Issue;
$model->project_id = $this->_project->id;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Issue']))
{
$model->attributes=$_POST['Issue'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
$model->image->saveAs(Yii::app()->basePath . '/../images/' . $model->image);
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Issue']))
{
$model->attributes=$_POST['Issue'];
$file_flyer = CUploadedFile::getInstance($model,'image');
if ((is_object($file_flyer) && get_class($file_flyer)==='CUploadedFile'))
//{
{
$model->image = $file_flyer;
}
if($model->save())
{
if (is_object($file_flyer))
{
$model->image->saveAs(Yii::app()->basePath.'/../images/'.$model->image);
//$this->render('update',array('model'=>$model,));
}
}
現在創建工作正常,如果你選擇一個文件的更新,包括但如果你不選擇一個文件的更新工作好它不會更新並將您重定向到視圖。
即使我不選擇一個文件,以便它仍然有當前文件,我希望它正在更新。