예제 #1
0
 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $model->date_create = date("Y-m-d");
     $model->date_update = date("Y-m-d");
     if ($model->load(Yii::$app->request->post())) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file && $model->validate()) {
             $model->file->saveAs(Yii::$app->basePath . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension);
         }
         $model->preview = '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post())) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->file->saveAs('uploads/' . $model->name . '.' . $model->file->extension);
         $model->cover = 'uploads/' . $model->name . '.' . $model->file->extension;
         if ($model->save()) {
             $response['message'] = 'success';
         } else {
             $response['message'] = 'fail';
         }
         return $response;
         //            return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }