add postModel

This commit is contained in:
Билай Станислав 2024-07-01 13:09:43 +03:00
parent c4bc65e5dc
commit b8c98693f8
5 changed files with 80 additions and 1 deletions

View File

@ -4,4 +4,5 @@ namespace src;
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
require "views/form.php"; require "views/post.php";
//require "views/form.php";

29
post.php Normal file
View File

@ -0,0 +1,29 @@
<?php
use src\debug\Debug;
use src\dto\InformationDTO;
use src\file_db_driver\FileDatabaseDriver;
use src\models\PostModel;
use src\Processing;
require_once "vendor/autoload.php";
ini_set("display_errors", true);
error_reporting(-1);
//$fileName = "Information.txt";
//$fileModeOpen = "a";
$post = new PostModel();
$post->load($_REQUEST);
$post->save();
$post1 = new PostModel();
$res = $post1->find(['author' => ['Stas']])->limit(10)->all();
$json = new Processing();
$infArr = $json->createJsonArray($post->labels(), $res, "form2");
$table = new \Itguild\Tables\ListJsonTable($infArr);
$table->create();
$table->render();

4
post.txt Normal file
View File

@ -0,0 +1,4 @@
autoincrement=id;last_id=2;table_name=post
id;author;post
1;Stas;Hello, world!!!
2;Stas;Hello, world!!!

31
src/models/PostModel.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace src\models;
use src\models\BaseModel;
class PostModel extends BaseModel
{
public int $status = 1;
public function file(): string
{
return "post.txt";
}
public function fillable(): array
{
return [
'author', 'post'
];
}
public function labels(): array
{
return [
'author' => 'Автор',
'post' => 'Пост'
];
}
}

14
views/post.php Normal file
View File

@ -0,0 +1,14 @@
<form action="post.php" target="_blank" method="post">
Автор:<br>
<label>
<input type = "text" name = "author" required size="50" autofocus placeholder="Автор">
</label> <br> <br>
Пост:<br>
<label>
<textarea name = "post" rows="10" cols="50" placeholder="Текст"></textarea>
</label> <br> <br>
<input type = "submit" value="Подтвердить">
<input type="reset">
</form>