backend/controllers/PostController.php
/**
     * Creates a new Post model.
     * If creation is successful, the browser will be redirected to the 'update' page.
     *
     * @param integer $type Post type ID
     * @throws \yii\web\ForbiddenHttpException
     * @throws \yii\web\NotFoundHttpException
     * @return mixed
     */
Creates a new Post model.
If creation is successful, the browser will be redirected to the 'update' page.


Creates a new Post model . If creation is successful the browser will be redirected to the ' update ' page .
public function actionCreate($type)
    {
        $model = new Post();
        $postType = $this->findPostType($type);
        $model->comment_status = Option::get('default_comment_status');
        if (!Yii::$app->user->can($postType->permission)) {
            throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
        }
        if ($model->load(Yii::$app->request->post())) {
            $model->type = $postType->id;
            $model->date = date('Y-m-d H:i:s', strtotime($model->date));
            if ($model->save()) {
                if ($termIds = Yii::$app->request->post('termIds')) {
                    foreach ($termIds as $termId) {
                        $termRelationship = new TermRelationship();
                        $termRelationship->setAttributes([
                            'term_id' => $termId,
                            'post_id' => $model->id,
                        ]);
                        if ($termRelationship->save() && $term = $this->findTerm($termId)) {
                            $term->updateAttributes(['count' => ++$term->count]);
                        }
                    }
                }
                if ($meta = Yii::$app->request->post('meta')) {
                    foreach ($meta as $name => $value) {
                        $model->setMeta($name, $value);
                    }
                }
                Yii::$app->getSession()->setFlash('success',
                    Yii::t('writesdown', '{type} successfully saved.', ['type' => $postType->singular_name, ]));
                return $this->redirect(['update', 'id' => $model->id]);
            }
        }
        return $this->render('create', [
            'model' => $model,
            'postType' => $postType,
        ]);
    }
public function actionCreate ( $ type ) { $ model = new Post ( ) ; $ postType = $ this -> findPostType ( $ type ) ; $ model -> comment_status = Option :: get ( 'default_comment_status' ) ; if ( ! Yii :: $ app -> user -> can ( $ postType -> permission ) ) { throw new ForbiddenHttpException ( Yii :: t ( 'writesdown' , 'You are not allowed to perform this action.' ) ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ model -> type = $ postType -> id ; $ model -> date = date ( 'Y-m-d H:i:s' , strtotime ( $ model -> date ) ) ; if ( $ model -> save ( ) ) { if ( $ termIds = Yii :: $ app -> request -> post ( 'termIds' ) ) { foreach ( $ termIds as $ termId ) { $ termRelationship = new TermRelationship ( ) ; $ termRelationship -> setAttributes ( [ 'term_id' => $ termId , 'post_id' => $ model -> id , ] ) ; if ( $ termRelationship -> save ( ) && $ term = $ this -> findTerm ( $ termId ) ) { $ term -> updateAttributes ( [ 'count' => ++ $ term -> count ] ) ; } } } if ( $ meta = Yii :: $ app -> request -> post ( 'meta' ) ) { foreach ( $ meta as $ name => $ value ) { $ model -> setMeta ( $ name , $ value ) ; } } Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , Yii :: t ( 'writesdown' , '{type} successfully saved.' , [ 'type' => $ postType -> singular_name , ] ) ) ; return $ this -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , 'postType' => $ postType , ] ) ; }
Creates a new Post model.
Creates a new Post model .