backend/controllers/PostTypeController.php
/**
     * Updates an existing PostType model.
     * If update is successful, the browser will be redirected to the 'view' page.
     *
     * @param integer $id
     * @return mixed
     */
Updates an existing PostType model.
If update is successful, the browser will be redirected to the 'view' page.

@param integer $id
@return mixed
Updates an existing PostType model . If update is successful the browser will be redirected to the ' view ' page . @param integer $id @return mixed
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'name');
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            PostTypeTaxonomy::deleteAll(['post_type_id' => $id]);
            $postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy');
            if ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds'])) {
                foreach ($taxonomyIds as $taxonomyId) {
                    $postTypeTaxonomy = new PostTypeTaxonomy();
                    $postTypeTaxonomy->setAttributes([
                        'post_type_id' => $model->id,
                        'taxonomy_id' => $taxonomyId,
                    ]);
                    $postTypeTaxonomy->save();
                }
            }
            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('update', [
            'model' => $model,
            'taxonomy' => new Taxonomy(),
            'taxonomies' => $taxonomies,
        ]);
    }
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ taxonomies = ArrayHelper :: map ( Taxonomy :: find ( ) -> all ( ) , 'id' , 'name' ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { PostTypeTaxonomy :: deleteAll ( [ 'post_type_id' => $ id ] ) ; $ postTypeTaxonomy = Yii :: $ app -> request -> post ( 'PostTypeTaxonomy' ) ; if ( $ taxonomyIds = Json :: decode ( $ postTypeTaxonomy [ 'taxonomyIds' ] ) ) { foreach ( $ taxonomyIds as $ taxonomyId ) { $ postTypeTaxonomy = new PostTypeTaxonomy ( ) ; $ postTypeTaxonomy -> setAttributes ( [ 'post_type_id' => $ model -> id , 'taxonomy_id' => $ taxonomyId , ] ) ; $ postTypeTaxonomy -> save ( ) ; } } return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } return $ this -> render ( 'update' , [ 'model' => $ model , 'taxonomy' => new Taxonomy ( ) , 'taxonomies' => $ taxonomies , ] ) ; }
Updates an existing PostType model.
Updates an existing PostType model .