Example #1
0
 /**
  * Creates a new Content model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('createContent')) {
         $model = new Content();
         $types = ArrayHelper::map(ContentType::find()->all(), 'id', 'name');
         if ($model->load(Yii::$app->request->post()) && Yii::$app->user->getId() != null) {
             $model->author = Yii::$app->user->getId();
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model, 'types' => $types]);
         }
     } else {
         Yii::$app->session->setFlash('error', 'İçerik oluşturma yetkiniz yok');
         $this->redirect(['index']);
     }
 }