diff --git a/.gitignore b/.gitignore index 17560c2..94ad469 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea vendor -.env \ No newline at end of file +.env +cache \ No newline at end of file diff --git a/app/controllers/Controller.php b/app/controllers/Controller.php new file mode 100644 index 0000000..33c9fca --- /dev/null +++ b/app/controllers/Controller.php @@ -0,0 +1,14 @@ +loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views'); + $this->twig = new \Twig\Environment($this->loader, ['cache' => 'app/views/cache']); + } +} \ No newline at end of file diff --git a/app/controllers/QuestionController.php b/app/controllers/QuestionController.php index 348ab34..6903b1f 100644 --- a/app/controllers/QuestionController.php +++ b/app/controllers/QuestionController.php @@ -3,10 +3,10 @@ namespace app\controllers; use app\models\Question; -class QuestionController{ +class QuestionController extends Controller{ public function actionCreate() { - require "app/views/questionCreate.php"; + echo $this->twig->render('questionCreate.html'); } public function actionGetQuestionsWithAnswers() diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index d74832d..9358687 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -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 . "
"; + $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(); } diff --git a/app/views/mainLayout.html b/app/views/mainLayout.html new file mode 100644 index 0000000..d0f79f1 --- /dev/null +++ b/app/views/mainLayout.html @@ -0,0 +1,14 @@ + + + + + Примеры шаблонизатора Twig + + +

HEADER

+{% block content %} +{% endblock %} +

FOOTER

+ + + \ No newline at end of file diff --git a/app/views/questionCreate.php b/app/views/questionCreate.html similarity index 80% rename from app/views/questionCreate.php rename to app/views/questionCreate.html index bdcfd25..4c75022 100644 --- a/app/views/questionCreate.php +++ b/app/views/questionCreate.html @@ -1,3 +1,6 @@ +{% extends "mainLayout.html" %} + +{% block content %}
Вопрос: