Ejemplo n.º 1
0
 /**
  * Creates a new Upload model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $username = Yii::$app->user->identity->username;
     $users = User::find()->all();
     $scholars = Scholar::find()->all();
     $model = new Upload();
     foreach ($users as $user) {
         foreach ($scholars as $scholar) {
             if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
                 $model->scholar_scholar_id = $scholar->scholar_id;
                 $model->scholar_school_school_id = $scholar->school_school_id;
                 if ($model->load(Yii::$app->request->post())) {
                     $model->file = UploadedFile::getInstance($model, 'file');
                     if ($model->file != null) {
                         $fileName = md5(time()) . $model->upload_file_name . "" . $model->scholar_scholar_id . "" . $model->file->name;
                         $model->file->saveAs('Forms/' . $fileName);
                         $model->upload_form = 'Forms/' . $fileName;
                     }
                     $model->save();
                     return $this->redirect(['index', 'id' => $model->upload_id]);
                 } else {
                     return $this->render('create', ['model' => $model]);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Upload model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Upload();
     if ($model->load(Yii::$app->request->post())) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file != null) {
             $fileName = md5(time()) . $model->upload_file_name . " ofScholarID " . $model->scholar_scholar_id . " FileName " . $model->file->name;
             $model->file->saveAs('Forms/' . $fileName);
             $model->upload_form = 'Forms/' . $fileName;
             //		$filePath = 'Forms'.'\'.$fileName.'.'.$model->file->extension;
         }
         $model->save();
         // return $this->redirect($model->uploadedForm)->send();
         return $this->redirect(['view', 'id' => $model->upload_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }