示例#1
0
 /**
  * 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();
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d');
         //Создаю уникальное имя картинки при сохранении используя дату вплоть до секунд
         $imageName = date('Y-m-d h:m:s');
         strval($imageName);
         $imageName = str_replace(' ', '-', $imageName);
         $imageName = str_replace(':', '-', $imageName);
         $model->photo = UploadedFile::getInstance($model, 'photo');
         $model->photo->saveAs('photo/' . $imageName . '.' . $model->photo->extension);
         $fullName = Yii::getAlias('@webroot') . '/photo/' . $imageName . '.' . $model->photo->extension;
         $img = Image::getImagine()->open($fullName);
         $size = $img->getSize();
         $ratio = $size->getWidth() / $size->getHeight();
         $width = 200;
         $height = round($width / $ratio);
         $box = new Box($width, $height);
         $img->resize($box)->save(Yii::getAlias('@webroot') . '/thumb/' . $imageName . '.' . $model->photo->extension);
         $delete = getcwd() . '/photo/' . $imageName . '.' . $model->photo->extension;
         $model->photo = Yii::getAlias('@web') . '/thumb/' . $imageName . '.' . $model->photo->extension;
         if (!unlink($delete)) {
             echo 'оригинал картинки не удалось удалить но если закоментировать эту проверку в контроллере то все будет работать только без удаления оригинала картинки';
             die;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * 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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#3
0
 /**
  * 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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->password = md5($email + $password);
         return $this->redirect(['view', 'employee_id' => $model->employee_id, 'position_id' => $model->position_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * 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();
     if ($model->load(Yii::$app->request->post()) && ($res = $model->save())) {
         $this->set_service_info($model->id, $_REQUEST['service_data']);
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'data_set' => $this->get_service_info()]);
     }
 }
示例#5
0
 /**
  * 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();
     $section_array = $this->getAllSection();
     $model->beforeSave(true);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'section_array' => $section_array]);
     }
 }
 /**
  * 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->token_forupload = substr(Yii::$app->getSecurity()->generateRandomString(), 10);
     if ($model->load(Yii::$app->request->post())) {
         $this->Uploads(false);
         $model->resume = UploadedFile::getInstance($model, 'resume');
         if ($model->resume && $model->validate()) {
             $fileName = md5($model->resume->baseName . time()) . '.' . $model->resume->extension;
             $image = $model->resume;
             $model->resume = $fileName;
             $image->saveAs('resumes/' . $fileName);
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->emp_id]);
             }
         } else {
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->emp_id]);
             }
         }
     }
     return $this->render('create', ['model' => $model, 'amphur' => [], 'district' => []]);
 }
示例#7
0
 /**
  * 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]);
     }
 }