luya\helpers\FileHelper::writeFile PHP Method

writeFile() public static method

Basic helper method to write files with exception capture. The fileName will auto wrapped trough the Yii::getAlias function.
public static writeFile ( string $fileName, string $content ) : boolean
$fileName string The path to the file with file name
$content string The content to store in this File
return boolean
    public static function writeFile($fileName, $content)
    {
        try {
            $response = file_put_contents(Yii::getAlias($fileName), $content);
            if ($response === false) {
                return false;
            }
        } catch (Exception $error) {
            return false;
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create a new ActiveWindow class based on you properties.
  */
 public function actionCreate()
 {
     $name = $this->prompt("Please enter a name for the Active Window:", ['required' => true]);
     $className = $this->createClassName($name, $this->suffix);
     $moduleId = $this->selectModule(['text' => 'What module should ' . $className . ' belong to?', 'onlyAdmin' => true]);
     $module = Yii::$app->getModule($moduleId);
     $folder = $module->basePath . DIRECTORY_SEPARATOR . 'aws';
     $file = $folder . DIRECTORY_SEPARATOR . $className . '.php';
     $content = $this->renderWindowClassView($className, $module->getNamespace() . '\\aws', $moduleId);
     FileHelper::createDirectory($folder);
     if (FileHelper::writeFile($file, $content)) {
         return $this->outputSuccess("The Active Window file '{$file}' has been writtensuccessfull.");
     }
     return $this->outputError("Error while writing the Actice Window file '{$file}'.");
 }
All Usage Examples Of luya\helpers\FileHelper::writeFile