Example #1
0
 /**
  * Creates a new Newsletter model.
  * If creation is successful, the browser will be redirected to the 'update' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Newsletter();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', __('Your changes have been saved successfully.'));
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Newsletter model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->isGuest || Yii::$app->user->identity->user_role != 4 && Yii::$app->user->identity->user_role != 3) {
         return $this->goHome();
     }
     $model = new Newsletter();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->newsletter_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionUpdate($id = null)
 {
     $model = new Newsletter();
     if ($model->load($_POST)) {
         $id = $_POST['Newsletter']['id'];
         if ($id) {
             $model = Newsletter::findOne($id);
             $model->attributes = $_POST['Newsletter'];
         }
         //Upload Images
         $img = \yii\web\UploadedFile::getInstance($model, 'images');
         if (isset($img) && count($img) > 0) {
             $mPath = $this->getPath();
             $mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $img->extension;
             //Upload Images
             if ($img->saveAs($mPath . $mPic)) {
                 $image = \Yii::$app->image->load($mPath . $mPic);
                 $image->resize(150, 248);
                 $image->save($mPath . '/' . $mPic);
                 $model->images = $this->getUrl() . $mPic;
             }
         }
         //Upload Documents
         $file = \yii\web\UploadedFile::getInstance($model, 'files');
         if (isset($file) && count($file) > 0) {
             $mPath = $this->getPath();
             //Upload Images
             if ($file->saveAs($mPath . $file)) {
                 $model->files = $this->getUrl() . $file;
             }
         }
         if ($model->save()) {
             $this->updateOrder();
             return $this->redirect(array('index'));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Newsletter::findOne($id);
     }
     return $this->render('update', ['model' => $model]);
 }