This commit is contained in:
2024-07-12 11:06:19 +03:00
12 changed files with 282 additions and 58 deletions

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

@ -3,10 +3,11 @@ namespace app\controllers;
use app\models\Question;
class QuestionController{
public function actionCreate(): void
class QuestionController extends Controller{
public function actionCreate()
{
require "app/views/questionCreate.php";
echo $this->twig->render('questionCreate.html');
}
public function actionGetQuestionsWithAnswers(): array

View File

@ -6,10 +6,12 @@ use app\helpers\Debug;
use app\models\Question;
use app\models\User;
class UserController {
class UserController extends Controller{
public function actionCreate(): void
{
require "app/views/userCreate.php";
// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
echo $this->twig->render('userCreate.html');
}
public function actionAdd(): void
@ -25,10 +27,15 @@ class UserController {
public function actionIndex(): void
{
// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
$i = 0;
foreach (User::all() as $user)
{
echo $user->username . "<br>";
$userArr[$i++] = $user;
}
echo $this->twig->render('userTable.html', ['userArr' => $userArr]);
}
public function actionView($id): void
@ -46,16 +53,19 @@ class UserController {
public function actionUpdate(): void
{
Debug::prn("Update");
require "app/views/userUpdate.php";
// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
echo $this->twig->render('userUpdate.html');
}
public function actionEdit(): void
{
$_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
$user = User::find($_REQUEST['id']);
$user->username = $_REQUEST['username'];
$user->email = $_REQUEST['email'];
$user->password = $_REQUEST['password'];
$user->password_hash = $_REQUEST['password_hash'];
$user->save();
}