Compare commits

...

3 Commits

Author SHA1 Message Date
91dc9194e0 kernel 2024-07-12 11:31:04 +03:00
6d38f62e8d merge 2024-07-12 11:06:19 +03:00
4273b8d490 some fix 2024-07-12 11:03:48 +03:00
13 changed files with 41 additions and 34 deletions

View File

@ -2,4 +2,7 @@ DB_HOST=localhost
DB_USER=root
DB_DRIVER=mysql
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
vendor
.env
cache
views_cache

View File

@ -1,14 +0,0 @@
<?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,19 +2,21 @@
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()
public function actionGetQuestionsWithAnswers(): array
{
return Question::with('AnswerController')->get()->toArray();
}
public function actionGetQuestionsWithUsers()
public function actionGetQuestionsWithUsers(): array
{
return Question::with('user')->get()->toArray();
}

View File

@ -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

View File

@ -11,7 +11,8 @@
"autoload": {
"psr-4": {
"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("/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']);

15
kernel/Controller.php Normal file
View File

@ -0,0 +1,15 @@
<?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']]);
}
}

View File

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