backend/controllers/PostController.php
/**
     * Updates an existing Post model.
     * If update is successful, the browser will be redirected to the 'view' page.
     *
     * @param integer $id
     * @throws \yii\web\ForbiddenHttpException
     * @throws \yii\web\NotFoundHttpException
     * @return mixed
     */
Updates an existing Post model.
If update is successful, the browser will be redirected to the 'view' page.


Updates an existing Post model . If update is successful the browser will be redirected to the ' view ' page .
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $this->getPermission($model);
        $postType = $model->postType;
        if ($model->load(Yii::$app->request->post())) {
            $model->date = date('Y-m-d H:i:s', strtotime($model->date));
            if ($model->save()) {
                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(['post/update', 'id' => $id]);
            }
        }
        return $this->render('update', [
            'model' => $model,
            'postType' => $postType,
        ]);
    }
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ postType = $ model -> postType ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ model -> date = date ( 'Y-m-d H:i:s' , strtotime ( $ model -> date ) ) ; if ( $ model -> save ( ) ) { 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 ( [ 'post/update' , 'id' => $ id ] ) ; } } return $ this -> render ( 'update' , [ 'model' => $ model , 'postType' => $ postType , ] ) ; }
Updates an existing Post model.
Updates an existing Post model .