Compare commits
3 Commits
ab0db2b320
...
91dc9194e0
Author | SHA1 | Date | |
---|---|---|---|
91dc9194e0 | |||
6d38f62e8d | |||
4273b8d490 |
@ -2,4 +2,7 @@ DB_HOST=localhost
|
|||||||
DB_USER=root
|
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
|
||||||
cache
|
views_cache
|
@ -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']);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,19 +2,21 @@
|
|||||||
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('questionCreate.html');
|
echo $this->twig->render('question_create.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionGetQuestionsWithAnswers()
|
public function actionGetQuestionsWithAnswers(): array
|
||||||
{
|
{
|
||||||
return Question::with('AnswerController')->get()->toArray();
|
return Question::with('AnswerController')->get()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionGetQuestionsWithUsers()
|
public function actionGetQuestionsWithUsers(): array
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
"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']);
|
||||||
|
15
kernel/Controller.php
Normal file
15
kernel/Controller.php
Normal 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']]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "mainLayout.html" %}
|
{% extends "main_layout.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="/admin/question" method="post">
|
<form action="/admin/question" method="post">
|
Loading…
Reference in New Issue
Block a user