frontend/controllers/PostController.php
/**
     * Creates a new Post model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Post model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Post model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Post();
        $author_id = Yii::$app->user->id;
        if (Yii::$app->request->post()) {
            $post = Yii::$app->request->post()['Post'];
            $post['author_id'] = $author_id;
            $model = new Post($post);
            $model->save();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
public function actionCreate ( ) { $ model = new Post ( ) ; $ author_id = Yii :: $ app -> user -> id ; if ( Yii :: $ app -> request -> post ( ) ) { $ post = Yii :: $ app -> request -> post ( ) [ 'Post' ] ; $ post [ 'author_id' ] = $ author_id ; $ model = new Post ( $ post ) ; $ model -> save ( ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } }
Creates a new Post model.
Creates a new Post model .