Compare commits
No commits in common. "91dc9194e009708190b497c9b3d34209dfcca230" and "ab0db2b320e7f37886675eac60a3a11319b1b062" have entirely different histories.
91dc9194e0
...
ab0db2b320
@ -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
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
.env
|
.env
|
||||||
views_cache
|
cache
|
14
app/controllers/Controller.php
Normal file
14
app/controllers/Controller.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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">
|
@ -11,8 +11,7 @@
|
|||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"app\\": "app/",
|
"app\\": "app/",
|
||||||
"migrations\\": "migrations/",
|
"migrations\\": "migrations/"
|
||||||
"kernel\\": "kernel/"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
index.php
24
index.php
@ -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']);
|
||||||
|
@ -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']]);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user