Esempio n. 1
0
 /**
  * Creates a new Teachers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Teachers();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
         $model->imageFile->name = time() . substr(strrchr($model->imageFile->name, '.'), 0);
         $model->upload();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }