Yii2保存多个文件

时间:2017-05-03 12:24:12

标签: pdo yii2

我尝试保存多个文件(手册:http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html

这是我的控制器代码:

public function actionUpdate($id)
{
    $model = $this->findModel($id);

    if ($model->load(Yii::$app->request->post())) {
        $model->thumb = UploadedFile::getInstance($model, 'thumb');
        $model->gallery = UploadedFile::getInstances($model, 'gallery');
        $model->thumb->saveAs('uploads/' . $model->thumb->baseName . '.' . $model->thumb->extension);
        foreach ($model->gallery as $file) {
            $file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);
        }
        if($model->validate() && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('update', [
            'model' => $model,
        ]);
    } else {
        return $this->render('update', [
            'model' => $model,
        ]);
    }
}

但它给了我这个例外:

Database Exception – yii\db\Exception

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: UPDATE `project` SET `thumb`='deliver.png', `gallery`=:qp1, `total_square`=221.4, `living_square`=133.6, `price`=150000, `floor`=1 WHERE `id`=1
Error Info: Array
(
[0] => HY093
[1] => 0
)
↵
Caused by: PDOException

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

in /var/www/map.dev/vendor/yiisoft/yii2/db/Command.php at line 846

有人可以帮忙吗?

0 个答案:

没有答案