Example #1
0
 /**
  * Creates a new Posts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Posts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //            return $this->redirect(['view', 'id' => $model->id]);
     } else {
         //            return $this->render('create', [
         //                'model' => $model,
         //            ]);
     }
 }
Example #2
0
 /**
  * Creates a new Posts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Posts();
     if ($model->load(Yii::$app->request->post())) {
         //upload file
         $model = $this->uploadImage($model);
         $model->date = date('d-m-Y');
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Posts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('createPost')) {
         $modelmedia = new Postm();
         $model = new Posts();
         $model->author = Yii::$app->user->identity->username;
         $model->createdBy = Yii::$app->user->id;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $modelmedia->postId = $model->id;
             $imagename = Yii::$app->security->generateRandomString();
             $modelmedia->media = UploadedFile::getInstance($modelmedia, 'media');
             if ($modelmedia->media != null) {
                 $modelmedia->media->saveAs(Yii::getAlias('@frontend/web/photo/') . $imagename . '.' . $modelmedia->media->extension);
                 $modelmedia->media = 'photo/' . $imagename . '.' . $modelmedia->media->extension;
                 $modelmedia->save(false);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'modelmedia' => $modelmedia]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }