controllers/PostController.php
/**
     * Updates an existing Post model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Updates an existing Post model.
If update is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Updates an existing Post model . If update is successful the browser will be redirected to the ' view ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionUpdate($id)
    {        
        $errors = [
            'post' => true,
            'postinqueue' => true,
            'postforms' => true,
        ];
        $modelPost = $this->findModel($id);
        $modelPostInQueue = new PostInQueue;
        $modelsForm = [
            new DescriptivePost,
            new ContactPost,
        ];
        if ($modelPost->load(Yii::$app->request->post()) && $modelPost->validate()){
            $post_id = 1;
            $modelPostInQueue->setPostId($post_id);
            if ($modelPostInQueue->load(Yii::$app->request->post()) && $modelPostInQueue->validate()){
                $modelsForm[$modelPost->type]->setPostId($post_id);
                if ($modelsForm[$modelPost->type]->load(Yii::$app->request->post()) && $modelsForm[$modelPost->type]->validate()){                                    
                    return $this->redirect(['view', 'id' => $post_id]);
                }
                else{
                    $errors['postforms'] = false;                    
                }
            }
            else{
                $errors['postinqueue'] = false;
            }
        }
        return $this->render('update', [
            'modelPost' => $modelPost,
            'PostInQueue' => $modelPostInQueue,
            'modelsForm' => $modelsForm,
            'forms' => $this->getForms($modelsForm),
            'attr_exceptions' => $this->getAttributeExceptions(),
        ]);
    }
public function actionUpdate ( $ id ) { $ errors = [ 'post' => true , 'postinqueue' => true , 'postforms' => true , ] ; $ modelPost = $ this -> findModel ( $ id ) ; $ modelPostInQueue = new PostInQueue ; $ modelsForm = [ new DescriptivePost , new ContactPost , ] ; if ( $ modelPost -> load ( Yii :: $ app -> request -> post ( ) ) && $ modelPost -> validate ( ) ) { $ post_id = 1 ; $ modelPostInQueue -> setPostId ( $ post_id ) ; if ( $ modelPostInQueue -> load ( Yii :: $ app -> request -> post ( ) ) && $ modelPostInQueue -> validate ( ) ) { $ modelsForm [ $ modelPost -> type ] -> setPostId ( $ post_id ) ; if ( $ modelsForm [ $ modelPost -> type ] -> load ( Yii :: $ app -> request -> post ( ) ) && $ modelsForm [ $ modelPost -> type ] -> validate ( ) ) { return $ this -> redirect ( [ 'view' , 'id' => $ post_id ] ) ; } else { $ errors [ 'postforms' ] = false ; } } else { $ errors [ 'postinqueue' ] = false ; } } return $ this -> render ( 'update' , [ 'modelPost' => $ modelPost , 'PostInQueue' => $ modelPostInQueue , 'modelsForm' => $ modelsForm , 'forms' => $ this -> getForms ( $ modelsForm ) , 'attr_exceptions' => $ this -> getAttributeExceptions ( ) , ] ) ; }
Updates an existing Post model.
Updates an existing Post model .
/*if (Yii::$app->request->post()){
            //echo array_sum($errors);
            //echo var_dump(Yii::$app->request->post());
        }

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }*/