public function actionSave()
    {
        if (Yii::$app->request->isPost) {
            // By default widget sends page key indicating the URL where the data was changed.
            $page = Yii::$app->request->post('page');

            // In case data has been previously saved let's find it for an update
            $model = Content::findOne(['page' => $page]);

            // In case it's not found because this is first time of saving it let's take new object instance
            if ($model === null) {
                $model = new Content();
            }

            // By default yii2-content-tools saves each editable region in 'contentToolsX' POST array key
            // where X is the next number starting from 0. In this example we've got only one region.
            $model->setAttributes([
                'data' => Yii::$app->request->post('contentTools0'),
                'page' => $page,
            ]);

            if (!$model->save()) {
                return $this->asJson(['errors' => $model->errors]);
            }

            return $this->asJson(true);
        }

        return $this->asJson(['errors' => ['No data sent in POST.']]);
    }
public function actionSave()
    {
        if (Yii::$app->request->isPost) {
            // By default widget sends page key indicating the URL where the data was changed.
            $page = Yii::$app->request->post('page');

            // In case data has been previously saved let's find it for an update
            $model = Content::findOne(['page' => $page]);

            // In case it's not found because this is first time of saving it let's take new object instance
            if ($model === null) {
                $model = new Content();
            }

            // By default yii2-content-tools saves each editable region in 'contentToolsX' POST array key
            // where X is the next number starting from 0. In this example we've got only one region.
            $model->setAttributes([
                'data' => Yii::$app->request->post('contentTools0'),
                'page' => $page,
            ]);

            if (!$model->save()) {
                return $this->asJson(['errors' => $model->errors]);
            }

            return $this->asJson(true);
        }

        return $this->asJson(['errors' => ['No data sent in POST.']]);
    }
public function actionSave ( ) { if ( Yii :: $ app -> request -> isPost ) { // By default widget sends page key indicating the URL where the data was changed. $ page = Yii :: $ app -> request -> post ( 'page' ) ; // In case data has been previously saved let's find it for an update $ model = Content :: findOne ( [ 'page' => $ page ] ) ; // In case it's not found because this is first time of saving it let's take new object instance if ( $ model === null ) { $ model = new Content ( ) ; } // By default yii2-content-tools saves each editable region in 'contentToolsX' POST array key // where X is the next number starting from 0. In this example we've got only one region. $ model -> setAttributes ( [ 'data' => Yii :: $ app -> request -> post ( 'contentTools0' ) , 'page' => $ page , ] ) ; if ( ! $ model -> save ( ) ) { return $ this -> asJson ( [ 'errors' => $ model -> errors ] ) ; } return $ this -> asJson ( true ) ; } return $ this -> asJson ( [ 'errors' => [ 'No data sent in POST.' ] ] ) ; }
This action handles saving the content.
Actual data is saved in database and represented by Content model.
@return string
This action handles saving the content . Actual data is saved in database and represented by Content model .