skeeks\cms\models\forms\ViewFileEditModel::saveFile PHP Method

saveFile() public method

public saveFile ( ) : boolean
return boolean
    public function saveFile()
    {
        if (is_writable($this->rootViewFile) && file_exists($this->rootViewFile)) {
            $file = fopen($this->rootViewFile, 'w');
            fwrite($file, $this->source);
            fclose($file);
            return true;
        }
        return false;
    }

Usage Example

Example #1
0
 public function actionViewFileEdit()
 {
     $rootViewFile = \Yii::$app->request->get('root-file');
     $model = new ViewFileEditModel(['rootViewFile' => $rootViewFile]);
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         if ($model->load(\Yii::$app->request->post())) {
             if (!$model->saveFile()) {
                 $rr->success = false;
                 $rr->message = "Не удалось сохранить файл.";
             }
             $rr->message = "Сохранено";
             $rr->success = true;
         }
         return $rr;
     }
     return $this->render($this->action->id, ['model' => $model]);
 }