diff --git a/.env.example b/.env.example index 47f3f24..2e77d26 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,7 @@ DB_HOST=localhost DB_USER=root DB_DRIVER=mysql DB_PASSWORD=123edsaqw -DB_NAME=mfw \ No newline at end of file +DB_NAME=mfw + +VIEWS_PATH=/views +VIEWS_CACHE_PATH=/views_cache \ No newline at end of file diff --git a/.gitignore b/.gitignore index 94ad469..ddd7975 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea vendor .env -cache \ No newline at end of file +views_cache \ No newline at end of file diff --git a/app/controllers/Controller.php b/app/controllers/Controller.php deleted file mode 100644 index 33c9fca..0000000 --- a/app/controllers/Controller.php +++ /dev/null @@ -1,14 +0,0 @@ -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 43b13e5..2dfaf3a 100644 --- a/app/controllers/QuestionController.php +++ b/app/controllers/QuestionController.php @@ -2,12 +2,13 @@ namespace app\controllers; use app\models\Question; +use kernel\Controller; class QuestionController extends Controller{ public function actionCreate() { - echo $this->twig->render('questionCreate.html'); + echo $this->twig->render('question_create.html.twig'); } public function actionGetQuestionsWithAnswers(): array diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 9358687..c610d56 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -2,9 +2,9 @@ namespace app\controllers; -use app\helpers\Debug; use app\models\Question; use app\models\User; +use kernel\Controller; class UserController extends Controller{ public function actionCreate(): void diff --git a/composer.json b/composer.json index 60ecba0..162bb7e 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "autoload": { "psr-4": { "app\\": "app/", - "migrations\\": "migrations/" + "migrations\\": "migrations/", + "kernel\\": "kernel/" } } } diff --git a/index.php b/index.php index 6d61acc..d3873c3 100644 --- a/index.php +++ b/index.php @@ -27,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']); diff --git a/kernel/Controller.php b/kernel/Controller.php new file mode 100644 index 0000000..0d82f01 --- /dev/null +++ b/kernel/Controller.php @@ -0,0 +1,15 @@ +loader = new \Twig\Loader\FilesystemLoader(ROOT_DIR . $_ENV['VIEWS_PATH']); + $this->twig = new \Twig\Environment($this->loader, ['cache' => ROOT_DIR . $_ENV['VIEWS_CACHE_PATH']]); + } +} \ No newline at end of file diff --git a/app/views/mainLayout.html b/views/main_layout.html.twig similarity index 100% rename from app/views/mainLayout.html rename to views/main_layout.html.twig diff --git a/app/views/questionCreate.html b/views/question_create.html.twig similarity index 86% rename from app/views/questionCreate.html rename to views/question_create.html.twig index 4c75022..afd7928 100644 --- a/app/views/questionCreate.html +++ b/views/question_create.html.twig @@ -1,4 +1,4 @@ -{% extends "mainLayout.html" %} +{% extends "main_layout.html.twig" %} {% block content %}
diff --git a/app/views/userCreate.html b/views/user_create.html.twig similarity index 100% rename from app/views/userCreate.html rename to views/user_create.html.twig diff --git a/app/views/userTable.html b/views/user_table.html.twig similarity index 100% rename from app/views/userTable.html rename to views/user_table.html.twig diff --git a/app/views/userUpdate.html b/views/user_update.html.twig similarity index 100% rename from app/views/userUpdate.html rename to views/user_update.html.twig