/**
  * Creates a new Pages model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Pages();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $this->validate($request, ['type' => 'required', 'content' => 'required|min:10']);
         $pageobj = new Pages();
         $pageobj->type = $request->input('type');
         $pageobj->content = htmlspecialchars($request->input('content'), ENT_NOQUOTES);
         $pageobj->is_active = true;
         $pageobj->save();
         return Redirect::to('/back/page/edit/' . $pageobj->id);
     } catch (Exception $e) {
         return Redirect::to('/back/page/create')->withwith('message', 'Oops! Something went wrong. Please try again later');
     }
 }
Exemple #3
0
 /**
  * Creates a new Pages model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!\Yii::$app->user->isGuest) {
         $model = new Pages();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
     $model = new LoginForm();
     if ($model->load(\Yii::$app->request->post()) && $model->login()) {
         $dataProvider = new ActiveDataProvider(['query' => Pages::find()]);
         return $this->render('index', ['dataProvider' => $dataProvider]);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }