我的控制器:
public function actionCreate()
{
$model = new CreateBookings();
if ($model->load(Yii::$app->request->post()))
{
$imageName = $model->primary_name;
$model->file = UploadedFile::getInstance($model, 'file');
$model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
$model->id_image = 'uploads/'.$imageName.'.'.$model->file->extension;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else
{
return $this->render('create', [
'model' => $model,
]);
}
}
在提交表单时出现此错误,不知道它有什么问题..
试过$model->save(false);
..但不能正常工作
答案 0 :(得分:3)
尝试使用public function actionCreate()
{
$model = new CreateBookings();
if ($model->load(Yii::$app->request->post()))
{
$imageName = $model->primary_name;
$model->file = UploadedFile::getInstance($model, 'file');
$model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
$model->id_image = 'uploads/'.$imageName.'.'.$model->file->extension;
if($model->save())
{
$lastInsertID = $model->getPrimaryKey();
return $this->redirect(['view', 'id' => $lastInsertID]);
}
else
{
// print_r($model->getErrors()); => check whether any validation errors are there
}
} else
{
return $this->render('create', [
'model' => $model,
]);
}
}
方法:
awk '{a[$1]+=$2; c[$1]++} END{for (i in a) printf "%d%s%.2f\n", i, OFS, a[i]/c[i]}' file
1 18.00
2 11.00
3 26.33
4 35.00
5 3.00