コード例 #1
0
ファイル: EmployeeController.php プロジェクト: sindotnet/cona
 /**
  * Creates a new Employee model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Employee();
     $model->suspended = '0';
     $companies = Company::find()->asArray()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         /** Upload Images okstmtcc **/
         //Upload Signature
         if ($model->uploadSignature() !== false) {
             $signature = UploadedFile::getInstance($model, 'signature');
             // store the source file name
             $model->signature = $signature->name;
             $ext = end(explode(".", $signature->name));
             // generate a unique file name
             $model->signature = Yii::$app->security->generateRandomString() . ".{$ext}";
             // the path to save file, you can set an uploadPath
             // in Yii::$app->params (as used in example below)
             $path = Yii::$app->params['signaturePath'] . $model->signature;
             if ($model->save()) {
                 $signature->saveAs($path);
             }
         }
         //Upload Profile Image
         if ($model->uploadProfile() !== false) {
             $profile_image = UploadedFile::getInstance($model, 'profile_image');
             // store the source file name
             $model->profile_image = $profile_image->name;
             $ext = end(explode(".", $profile_image->name));
             // generate a unique file name
             $model->profile_image = Yii::$app->security->generateRandomString() . ".{$ext}";
             // the path to save file, you can set an uploadPath
             // in Yii::$app->params (as used in example below)
             $path = Yii::$app->params['profilePath'] . $model->profile_image;
             if ($model->save()) {
                 $profile_image->saveAs($path);
             }
         }
         //Upload NRIC Front
         if ($model->uploadNRICfront() !== false) {
             $NRIC_front = UploadedFile::getInstance($model, 'NRIC_front');
             // store the source file name
             $model->NRIC_front = $NRIC_front->name;
             $ext = end(explode(".", $NRIC_front->name));
             // generate a unique file name
             $model->NRIC_front = Yii::$app->security->generateRandomString() . ".{$ext}";
             // the path to save file, you can set an uploadPath
             // in Yii::$app->params (as used in example below)
             $path = Yii::$app->params['nricPath'] . $model->NRIC_front;
             if ($model->save()) {
                 $NRIC_front->saveAs($path);
             }
         }
         //Upload NRIC Back
         if ($model->uploadNRICback() !== false) {
             $NRIC_back = UploadedFile::getInstance($model, 'NRIC_back');
             // store the source file name
             $model->NRIC_back = $NRIC_back->name;
             $ext = end(explode(".", $NRIC_back->name));
             // generate a unique file name
             $model->NRIC_back = Yii::$app->security->generateRandomString() . ".{$ext}";
             // the path to save file, you can set an uploadPath
             // in Yii::$app->params (as used in example below)
             $path = Yii::$app->params['nricPath'] . $model->NRIC_back;
             if ($model->save()) {
                 $NRIC_back->saveAs($path);
             }
         }
         /** Upload Images okstmtcc **/
         return $this->redirect(['update', 'id' => $model->employee_id]);
     } else {
         return $this->render('create', ['model' => $model, 'companies' => $companies]);
     }
 }