Compare commits

..

No commits in common. "91dc9194e009708190b497c9b3d34209dfcca230" and "ab0db2b320e7f37886675eac60a3a11319b1b062" have entirely different histories.

13 changed files with 34 additions and 41 deletions

View File

@ -3,6 +3,3 @@ DB_USER=root
DB_DRIVER=mysql DB_DRIVER=mysql
DB_PASSWORD=123edsaqw DB_PASSWORD=123edsaqw
DB_NAME=mfw DB_NAME=mfw
VIEWS_PATH=/views
VIEWS_CACHE_PATH=/views_cache

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
.idea .idea
vendor vendor
.env .env
views_cache cache

View File

@ -0,0 +1,14 @@
<?php
namespace app\controllers;
class Controller
{
protected \Twig\Loader\FilesystemLoader $loader;
protected \Twig\Environment $twig;
public function __construct()
{
$this->loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
$this->twig = new \Twig\Environment($this->loader, ['cache' => 'app/views/cache']);
}
}

View File

@ -2,21 +2,19 @@
namespace app\controllers; namespace app\controllers;
use app\models\Question; use app\models\Question;
use kernel\Controller;
class QuestionController extends Controller{ class QuestionController extends Controller{
public function actionCreate() public function actionCreate()
{ {
echo $this->twig->render('question_create.html.twig'); echo $this->twig->render('questionCreate.html');
} }
public function actionGetQuestionsWithAnswers(): array public function actionGetQuestionsWithAnswers()
{ {
return Question::with('AnswerController')->get()->toArray(); return Question::with('AnswerController')->get()->toArray();
} }
public function actionGetQuestionsWithUsers(): array public function actionGetQuestionsWithUsers()
{ {
return Question::with('user')->get()->toArray(); return Question::with('user')->get()->toArray();
} }

View File

@ -2,9 +2,9 @@
namespace app\controllers; namespace app\controllers;
use app\helpers\Debug;
use app\models\Question; use app\models\Question;
use app\models\User; use app\models\User;
use kernel\Controller;
class UserController extends Controller{ class UserController extends Controller{
public function actionCreate(): void public function actionCreate(): void

View File

@ -1,4 +1,4 @@
{% extends "main_layout.html.twig" %} {% extends "mainLayout.html" %}
{% block content %} {% block content %}
<form action="/admin/question" method="post"> <form action="/admin/question" method="post">

View File

@ -11,8 +11,7 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"app\\": "app/", "app\\": "app/",
"migrations\\": "migrations/", "migrations\\": "migrations/"
"kernel\\": "kernel/"
} }
} }
} }

View File

@ -27,18 +27,18 @@ $router->group(["prefix" => "admin"], function (RouteCollector $router){
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']); $router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']); $router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
}); });
$router->group(["prefix" => "question"], function (RouteCollector $router){ // $router->group(["prefix" => "question"], function (RouteCollector $router){
$router->get('/create', [QuestionController::class, 'actionCreate']); // $router->get('/create', [QuestionController::class, 'actionCreate']);
$router->get('/update', [QuestionController::class, 'actionUpdate']); // $router->get('/update', [QuestionController::class, 'actionUpdate']);
$router->get('/delete/{id}', [QuestionController::class, 'actionDelete']); // $router->get('/delete/{id}', [QuestionController::class, 'actionDelete']);
$router->get('/', [QuestionController::class, 'actionIndex']); // $router->get('/', [QuestionController::class, 'actionIndex']);
$router->get('/{id}', [QuestionController::class, 'actionView']); // $router->get('/{id}', [QuestionController::class, 'actionView']);
$router->post("/", [QuestionController::class, 'actionAdd']); // $router->post("/", [QuestionController::class, 'actionAdd']);
$router->post("/edit", [QuestionController::class, 'actionEdit']); // $router->post("/edit", [QuestionController::class, 'actionEdit']);
}); // });
$router->group(["prefix" => "post"], function (RouteCollector $router){ // $router->group(["prefix" => "post"], function (RouteCollector $router){
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']); // $router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
}); // });
}); });
$router->get('/allQuestions', [QuestionController::class, 'actionViewAllQuestions']); $router->get('/allQuestions', [QuestionController::class, 'actionViewAllQuestions']);

View File

@ -1,15 +0,0 @@
<?php
namespace kernel;
class Controller
{
protected \Twig\Loader\FilesystemLoader $loader;
protected \Twig\Environment $twig;
public function __construct()
{
$this->loader = new \Twig\Loader\FilesystemLoader(ROOT_DIR . $_ENV['VIEWS_PATH']);
$this->twig = new \Twig\Environment($this->loader, ['cache' => ROOT_DIR . $_ENV['VIEWS_CACHE_PATH']]);
}
}