Вид Create
Код: Выделить всё
public function actionCreate(){
$model = new Order([
'dirName' => date('Y-m-d'),
]);
if ($model->load(Yii::$app->request->post())){
$model->docFile = UploadedFile::getInstance($model, 'docFile');
if ($model->validate()) {
if($model->path = $model->upload()) {
if ($model->save(false)) {
Yii::$app->session->setFlash('success', "Документ {$model->name} добавлен");
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
}
return $this->render('create', [
'model' => $model,
]);
}
Код: Выделить всё
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())){
$model->docFile = UploadedFile::getInstance($model, 'docFile');
if ($model->validate()) {
if($model->path = $model->upload()) {
if ($model->save(false)) {
Yii::$app->session->setFlash('success', "Документ загружен");
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
}
return $this->render('update', [
'model' => $model,
]);
}