Ejemplo n.º 1
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!\Yii::$app->user->can('articles.article.create')) {
         $this->accessDenied();
     }
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($p = null)
 {
     if (!\Yii::$app->user->can('articles.article.create')) {
         $this->accessDenied();
     }
     // FIXME: check permission for parent
     $article = new Article();
     $article->parentid = intval($p);
     $article->updated_at = time();
     $article->title = '';
     $article->authorid = \Yii::$app->user->id;
     $article->save(false);
     $rev = new Revision();
     $rev->articleid = $article->id;
     $rev->updated_at = time();
     $rev->title = '';
     $rev->role = Revision::ROLE_CURRENT;
     $rev->save(false);
     return $this->redirect(['update', 'id' => $article->id, 'rev' => $rev->id]);
     if ($rev->load(Yii::$app->request->post()) && $rev->save()) {
         return $this->redirect(['view', 'id' => $rev->articleid, 'rev' => $rev->id]);
     } else {
         return $this->render('create', ['rev' => $rev]);
     }
 }