Yii2 how to make automatic generation of the files?

Good day! Tell me how to implement the automatic generation of the files? For example, there is a folder site/pages with static pages. I want to implement in admin panel create new static pages and after creating automatically in this folder were generated file
June 14th 19 at 19:04
2 answers
June 14th 19 at 19:06
Solution
Why do files generate? The content to store in our religion does not allow? Well, it's the lyrics:
php.net/manual/ru/function.file-put-contents.php
Take the content and write to a file:
$path = 'some/path/to/my/file/';
$name = 'some_file_name.html';
$content = '<h1>my html</h1>';
file_put_contents($path.$name,$content);

But what's yii?
I got it, thanks, but I'm just learning and your lessons))) - April_Wucker commented on June 14th 19 at 19:15
Thought it can be solved by means of yii. - April_Wucker commented on June 14th 19 at 19:09
yii is a php. Why write a method so if it is in php? - Henderson_Beat commented on June 14th 19 at 19:12
And what's the point in generating html? In my opinion it is easier to have a table in the database for pages and template, standard, CRUD, etc. Why form html and save as files? - Henderson_Beat commented on June 14th 19 at 19:18
I do not argue, it's easier. For self-education. Bitrix approximately by such principle works when you create pages and sections are generated files, just was curious about the implementation - April_Wucker commented on June 14th 19 at 19:21
Then you can complicate the use of model validation and template and to do so in action:
public function actionCreate()
{
 $model = new Page();
 if ($model->load(Yii::$app->request->post())) {
 $path = Yii::getAlias('@pages');
file_put_contents(
$path.$model->name,
$this->render('html_template',['model'=>$model])
);
 return $this->redirect(['view', 'id' => $model->id]);
 } else {
 return $this->render('create', [
 'model' => $model,
]);
}
 }
- Henderson_Beat commented on June 14th 19 at 19:24
Thank you very much - April_Wucker commented on June 14th 19 at 19:27
June 14th 19 at 19:08
Good afternoon.
As one of the options:
1) a Form to send to the server
2) the Visual editor in the form
3) In the controller action using file_put_contents()
4) the pages Directory needs to have write permissions.
Thank you - April_Wucker commented on June 14th 19 at 19:11

Find more questions by tags PHP