diff --git a/.gitignore b/.gitignore
index 17560c2..94ad469 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.idea
vendor
-.env
\ No newline at end of file
+.env
+cache
\ No newline at end of file
diff --git a/app/controllers/Controller.php b/app/controllers/Controller.php
new file mode 100644
index 0000000..33c9fca
--- /dev/null
+++ b/app/controllers/Controller.php
@@ -0,0 +1,14 @@
+loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
+ $this->twig = new \Twig\Environment($this->loader, ['cache' => 'app/views/cache']);
+ }
+}
\ No newline at end of file
diff --git a/app/controllers/QuestionController.php b/app/controllers/QuestionController.php
index 348ab34..6903b1f 100644
--- a/app/controllers/QuestionController.php
+++ b/app/controllers/QuestionController.php
@@ -3,10 +3,10 @@ namespace app\controllers;
use app\models\Question;
-class QuestionController{
+class QuestionController extends Controller{
public function actionCreate()
{
- require "app/views/questionCreate.php";
+ echo $this->twig->render('questionCreate.html');
}
public function actionGetQuestionsWithAnswers()
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index d74832d..9358687 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -6,10 +6,12 @@ use app\helpers\Debug;
use app\models\Question;
use app\models\User;
-class UserController {
+class UserController extends Controller{
public function actionCreate(): void
{
- require "app/views/userCreate.php";
+// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
+// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
+ echo $this->twig->render('userCreate.html');
}
public function actionAdd(): void
@@ -25,10 +27,15 @@ class UserController {
public function actionIndex(): void
{
+// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
+// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
+
+ $i = 0;
foreach (User::all() as $user)
{
- echo $user->username . "
";
+ $userArr[$i++] = $user;
}
+ echo $this->twig->render('userTable.html', ['userArr' => $userArr]);
}
public function actionView($id): void
@@ -46,16 +53,19 @@ class UserController {
public function actionUpdate(): void
{
- Debug::prn("Update");
- require "app/views/userUpdate.php";
+// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
+// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
+ echo $this->twig->render('userUpdate.html');
}
public function actionEdit(): void
{
+ $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
+
$user = User::find($_REQUEST['id']);
$user->username = $_REQUEST['username'];
$user->email = $_REQUEST['email'];
- $user->password = $_REQUEST['password'];
+ $user->password_hash = $_REQUEST['password_hash'];
$user->save();
}
diff --git a/app/views/mainLayout.html b/app/views/mainLayout.html
new file mode 100644
index 0000000..d0f79f1
--- /dev/null
+++ b/app/views/mainLayout.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Примеры шаблонизатора Twig
+
+
+HEADER
+{% block content %}
+{% endblock %}
+FOOTER
+
+
+
\ No newline at end of file
diff --git a/app/views/questionCreate.php b/app/views/questionCreate.html
similarity index 80%
rename from app/views/questionCreate.php
rename to app/views/questionCreate.html
index bdcfd25..4c75022 100644
--- a/app/views/questionCreate.php
+++ b/app/views/questionCreate.html
@@ -1,3 +1,6 @@
+{% extends "mainLayout.html" %}
+
+{% block content %}
\ No newline at end of file
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/views/userCreate.php b/app/views/userCreate.html
similarity index 77%
rename from app/views/userCreate.php
rename to app/views/userCreate.html
index 1871424..4a83659 100644
--- a/app/views/userCreate.php
+++ b/app/views/userCreate.html
@@ -1,3 +1,6 @@
+{% extends "mainLayout.html" %}
+
+{% block content %}
\ No newline at end of file
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/views/userTable.html b/app/views/userTable.html
new file mode 100644
index 0000000..e16d8f7
--- /dev/null
+++ b/app/views/userTable.html
@@ -0,0 +1,26 @@
+{% extends "mainLayout.html" %}
+
+{% block content %}
+
+
+
+ id |
+ Username |
+ Email |
+ Created at |
+ Updated at |
+
+
+
+ {% for users in userArr %}
+
+ {{ users.id }} |
+ {{ users.username }} |
+ {{ users.email }} |
+ {{ users.created_at }} |
+ {{ users.updated_at }} |
+
+ {% endfor %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/views/userUpdate.php b/app/views/userUpdate.html
similarity index 78%
rename from app/views/userUpdate.php
rename to app/views/userUpdate.html
index 2fb939f..01f2ca2 100644
--- a/app/views/userUpdate.php
+++ b/app/views/userUpdate.html
@@ -1,3 +1,6 @@
+{% extends "mainLayout.html" %}
+
+{% block content %}
\ No newline at end of file
+
+{% endblock %}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 21ecb37..60ecba0 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,8 @@
"require": {
"illuminate/database": "^11.14",
"craft-group/phroute": "^2.1",
- "vlucas/phpdotenv": "^5.6"
+ "vlucas/phpdotenv": "^5.6",
+ "twig/twig": "^3.0"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index a20cbf4..5d9d1e5 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "0f18467a4a4a8e17b3a359c92f94a062",
+ "content-hash": "ec1e05ff0752e8d6ad1df75a5cae6188",
"packages": [
{
"name": "brick/math",
@@ -337,16 +337,16 @@
},
{
"name": "illuminate/collections",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
- "reference": "358fd6dcce6927ee9d7cf520fa619f4597020d52"
+ "reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/collections/zipball/358fd6dcce6927ee9d7cf520fa619f4597020d52",
- "reference": "358fd6dcce6927ee9d7cf520fa619f4597020d52",
+ "url": "https://api.github.com/repos/illuminate/collections/zipball/9bf68f03bbe05d38c9bd99bac8798c0de61f8478",
+ "reference": "9bf68f03bbe05d38c9bd99bac8798c0de61f8478",
"shasum": ""
},
"require": {
@@ -388,11 +388,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-06-28T20:14:10+00:00"
+ "time": "2024-07-02T20:54:37+00:00"
},
{
"name": "illuminate/conditionable",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/conditionable.git",
@@ -438,16 +438,16 @@
},
{
"name": "illuminate/container",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
- "reference": "280405e0b577504b97feae0e7c7f5399816ccff1"
+ "reference": "49183db6643a7efbe9902ca379b8f8a55c802f88"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/container/zipball/280405e0b577504b97feae0e7c7f5399816ccff1",
- "reference": "280405e0b577504b97feae0e7c7f5399816ccff1",
+ "url": "https://api.github.com/repos/illuminate/container/zipball/49183db6643a7efbe9902ca379b8f8a55c802f88",
+ "reference": "49183db6643a7efbe9902ca379b8f8a55c802f88",
"shasum": ""
},
"require": {
@@ -485,20 +485,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-07-02T15:41:17+00:00"
+ "time": "2024-07-03T21:04:00+00:00"
},
{
"name": "illuminate/contracts",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
- "reference": "eb8ccfbc5905c5631712d157cccdd7bc9db692e0"
+ "reference": "be935e9d9115a57be74d20176f43fa8a207029f3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/contracts/zipball/eb8ccfbc5905c5631712d157cccdd7bc9db692e0",
- "reference": "eb8ccfbc5905c5631712d157cccdd7bc9db692e0",
+ "url": "https://api.github.com/repos/illuminate/contracts/zipball/be935e9d9115a57be74d20176f43fa8a207029f3",
+ "reference": "be935e9d9115a57be74d20176f43fa8a207029f3",
"shasum": ""
},
"require": {
@@ -533,20 +533,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-07-01T21:58:24+00:00"
+ "time": "2024-07-09T13:57:38+00:00"
},
{
"name": "illuminate/database",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/database.git",
- "reference": "6576f6fcc871a6ad173b6e246e8d2c63cd7cfe1a"
+ "reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/database/zipball/6576f6fcc871a6ad173b6e246e8d2c63cd7cfe1a",
- "reference": "6576f6fcc871a6ad173b6e246e8d2c63cd7cfe1a",
+ "url": "https://api.github.com/repos/illuminate/database/zipball/9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7",
+ "reference": "9b7b13d2d9175ae9c07d4744d8f7d5b07e7264a7",
"shasum": ""
},
"require": {
@@ -601,11 +601,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-07-02T15:56:54+00:00"
+ "time": "2024-07-08T15:08:27+00:00"
},
{
"name": "illuminate/macroable",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@@ -651,16 +651,16 @@
},
{
"name": "illuminate/support",
- "version": "v11.14.0",
+ "version": "v11.15.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
- "reference": "a8f299ed76d52fc048decada3571628e65fa5c41"
+ "reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/support/zipball/a8f299ed76d52fc048decada3571628e65fa5c41",
- "reference": "a8f299ed76d52fc048decada3571628e65fa5c41",
+ "url": "https://api.github.com/repos/illuminate/support/zipball/b551f6cbecc607bcaf520eb3fc1933db9b1398f2",
+ "reference": "b551f6cbecc607bcaf520eb3fc1933db9b1398f2",
"shasum": ""
},
"require": {
@@ -721,7 +721,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-07-01T21:58:57+00:00"
+ "time": "2024-07-08T14:46:56+00:00"
},
{
"name": "nesbot/carbon",
@@ -1130,6 +1130,73 @@
],
"time": "2024-05-31T14:57:53+00:00"
},
+ {
+ "name": "symfony/deprecation-contracts",
+ "version": "v3.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/deprecation-contracts.git",
+ "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1",
+ "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=8.1"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "3.5-dev"
+ },
+ "thanks": {
+ "name": "symfony/contracts",
+ "url": "https://github.com/symfony/contracts"
+ }
+ },
+ "autoload": {
+ "files": [
+ "function.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "A generic function and convention to trigger deprecation notices",
+ "homepage": "https://symfony.com",
+ "support": {
+ "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2024-04-18T09:32:20+00:00"
+ },
{
"name": "symfony/polyfill-ctype",
"version": "v1.30.0",
@@ -1617,6 +1684,85 @@
],
"time": "2024-04-18T09:32:20+00:00"
},
+ {
+ "name": "twig/twig",
+ "version": "v3.10.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/twigphp/Twig.git",
+ "reference": "67f29781ffafa520b0bbfbd8384674b42db04572"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/67f29781ffafa520b0bbfbd8384674b42db04572",
+ "reference": "67f29781ffafa520b0bbfbd8384674b42db04572",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.2.5",
+ "symfony/deprecation-contracts": "^2.5|^3",
+ "symfony/polyfill-ctype": "^1.8",
+ "symfony/polyfill-mbstring": "^1.3",
+ "symfony/polyfill-php80": "^1.22"
+ },
+ "require-dev": {
+ "psr/container": "^1.0|^2.0",
+ "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0"
+ },
+ "type": "library",
+ "autoload": {
+ "files": [
+ "src/Resources/core.php",
+ "src/Resources/debug.php",
+ "src/Resources/escaper.php",
+ "src/Resources/string_loader.php"
+ ],
+ "psr-4": {
+ "Twig\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com",
+ "homepage": "http://fabien.potencier.org",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Twig Team",
+ "role": "Contributors"
+ },
+ {
+ "name": "Armin Ronacher",
+ "email": "armin.ronacher@active-4.com",
+ "role": "Project Founder"
+ }
+ ],
+ "description": "Twig, the flexible, fast, and secure template language for PHP",
+ "homepage": "https://twig.symfony.com",
+ "keywords": [
+ "templating"
+ ],
+ "support": {
+ "issues": "https://github.com/twigphp/Twig/issues",
+ "source": "https://github.com/twigphp/Twig/tree/v3.10.3"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/twig/twig",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2024-05-16T10:04:27+00:00"
+ },
{
"name": "vlucas/phpdotenv",
"version": "v5.6.0",
@@ -1784,5 +1930,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
- "plugin-api-version": "2.3.0"
+ "plugin-api-version": "2.6.0"
}
diff --git a/index.php b/index.php
index 49ba953..6d61acc 100644
--- a/index.php
+++ b/index.php
@@ -14,7 +14,6 @@ use app\controllers\PostController;
use app\helpers\Debug;
use Phroute\Phroute\RouteCollector;
-
$router = new RouteCollector();
$router->get('/', [MainController::class, 'actionIndex']);
$router->get('/example', [MainController::class, 'actionExample']);
@@ -28,18 +27,18 @@ $router->group(["prefix" => "admin"], function (RouteCollector $router){
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
});
- $router->group(["prefix" => "question"], function (RouteCollector $router){
- $router->get('/create', [QuestionController::class, 'actionCreate']);
- $router->get('/update', [QuestionController::class, 'actionUpdate']);
- $router->get('/delete/{id}', [QuestionController::class, 'actionDelete']);
- $router->get('/', [QuestionController::class, 'actionIndex']);
- $router->get('/{id}', [QuestionController::class, 'actionView']);
- $router->post("/", [QuestionController::class, 'actionAdd']);
- $router->post("/edit", [QuestionController::class, 'actionEdit']);
- });
- $router->group(["prefix" => "post"], function (RouteCollector $router){
- $router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
- });
+// $router->group(["prefix" => "question"], function (RouteCollector $router){
+// $router->get('/create', [QuestionController::class, 'actionCreate']);
+// $router->get('/update', [QuestionController::class, 'actionUpdate']);
+// $router->get('/delete/{id}', [QuestionController::class, 'actionDelete']);
+// $router->get('/', [QuestionController::class, 'actionIndex']);
+// $router->get('/{id}', [QuestionController::class, 'actionView']);
+// $router->post("/", [QuestionController::class, 'actionAdd']);
+// $router->post("/edit", [QuestionController::class, 'actionEdit']);
+// });
+// $router->group(["prefix" => "post"], function (RouteCollector $router){
+// $router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
+// });
});
$router->get('/allQuestions', [QuestionController::class, 'actionViewAllQuestions']);