Yii2:无法更新多个映像


Yii2: Not able to Update multiple Images

In Controller

    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
         if ($model->load(Yii::$app->request->post())) 
        { 
            $imageName = $model->room_type;
            $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
            $all_files_paths = [];
                 foreach ($model->imageFiles as $file_instance) 
                 {
                   $path = 'uploads/room_img/' . $file_instance->baseName . '.' . $file_instance->extension;
                   $file_instance->saveAs($path);
                    $all_files_pathes []= $path;
                    $model->images .= $path . ';';
                 }
            $model->save(false);
            return $this->redirect(['view', 'id' => $model->id]);
 }
        else 
        {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

在"规则"部分中

[['imageFiles'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg', 'maxFiles' => 4,'skipOnEmpty' => true, 'on' => 'update-photo-upload'],

尝试使用scenario但它返回视图,图像没有变化。

上传多个图像文件并在数据库中存储路径,例如

uploads/room_img/1059.jpg;uploads/room_img/1060.jpg;uploads/room_img/1064.jpg;

我在数据库中插入多个文件,由;分隔,无法更新图像的路径

动作创建()

public function actionCreate()
    {
        $model = new RoomTypes();
        if ($model->load(Yii::$app->request->post())) 
        { 
            $imageName = $model->room_type;
            $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
            $all_files_paths = [];
                 foreach ($model->imageFiles as $file_instance) 
                 {
                   $path = 'uploads/room_img/' . $file_instance->baseName . '.' . $file_instance->extension;
                   $file_instance->saveAs($path);
                    $all_files_pathes []= $path;
                    $model->images .= $path . ';';
                 }
     $model->save(false);
     return $this->redirect(['view', 'id' => $model->id]);
 }
        else 
        {
            return $this->render('create', 
                [
                'model' => $model,
            ]);
        }
    }
public function actionUpdate($id)
{
    $model = $this->findModel($id);
    $model->scenario = 'update-photo-upload';
    $oldFiles = explode( ";", $model->imageFiles);
    if ($model->load(Yii::$app->request->post())) {
       foreach ($oldFiles as $actFile)  {
               if (trim($actFile) != '') {
                 unlink( 'uploads/room_img/' . $actFile);
               }
        } 
        $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
        $all_files_paths = [];
             foreach ($model->imageFiles as $file_instance) 
             {
               $path = 'uploads/room_img/' . $file_instance->baseName . '.' . $file_instance->extension;
               $file_instance->saveAs($path);
                $all_files_pathes []= $path;
                $model->images .= $path . ';';
             }
    $model->save(false);
    return $this->redirect(['view', 'id' => $model->id]);
    } 
    else 
    {
        return $this->render('update', [
            'model' => $model,
        ]);
    }
}