示例#1
0
 /**
  * Creates a new Services model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($id)
 {
     $model = new Services();
     if ($model->load(Yii::$app->request->post())) {
         $imageFile = UploadedFile::getInstance($model, 'imageFile');
         if ($imageFile && $imageFile->tempName) {
             $model->imageFile = $imageFile;
             if ($model->validate(['imageFile'])) {
                 $makedir = new Makedir($imageFile->name, Yii::getAlias('@webroot'), 'uploads/services', 'Y m d');
                 $file = Yii::getAlias('@webroot') . $makedir->GetResult()['path'] . $makedir->GetResult()['file'];
                 $model->imageFile->saveAs($file);
                 $model->picture = $makedir->GetResult()['file'];
                 $model->path_picture = $makedir->GetResult()['path'];
                 $model->imageFile = $makedir->GetResult()['file'];
                 Image::thumbnail($file, 100, 75)->save(Yii::getAlias('@webroot') . $makedir->GetResult()['path'] . 'small' . $makedir->GetResult()['file'], ['quality' => 80]);
                 Image::thumbnail($file, 370, 278)->save(Yii::getAlias('@webroot') . $makedir->GetResult()['path'] . 'thumb' . $makedir->GetResult()['file'], ['quality' => 80]);
                 Image::thumbnail($file, 1024, 768)->save(Yii::getAlias('@webroot') . $makedir->GetResult()['path'] . 'big' . $makedir->GetResult()['file'], ['quality' => 80]);
             }
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $model->loadDefaultValues();
             $model->parent_id = $id;
             return $this->render('create', ['model' => $model, 'id' => $id]);
         }
     } else {
         $model->loadDefaultValues();
         $model->parent_id = $id;
         return $this->render('create', ['model' => $model, 'id' => $id]);
     }
 }
示例#2
0
 /**
  * Creates a new Services model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Services();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Services model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Services();
     if ($model->load(Yii::$app->request->post())) {
         $model->service_status = 'Y';
         if ($model->save()) {
             Yii::$app->session->setFlash('success', 'Layanan berhasil disimpan');
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }