Пробуем подключить пародию на шаблонизатор.

This commit is contained in:
lopar 2020-09-30 13:03:05 +03:00
parent 5ac30becb7
commit e4343f28b5
2 changed files with 25 additions and 21 deletions

21
classes/Template.php Normal file
View File

@ -0,0 +1,21 @@
<?php
# Date: 30.09.2020 (09:42)
abstract class Template
{
public function __construct()
{
//Ничего не генерируем, обращаемся к статике сразу.
}
public static function header($title = null)
{
return <<<HTML_HEADER
<!doctype html>
<html lang="ru">
<meta charset="utf-8">
<link href="/css/main.css" rel="stylesheet">
<title>$title</title>
HTML_HEADER;
}
}

23
inf.php
View File

@ -7,29 +7,15 @@ $userInfo = new UserInfo($login);
$presentsModel = new PresentsModel($userInfo->id);
$presentsList = $presentsModel->getAllPresents();
$userInfo->watcher_id = $userInfo->id ?? null;
if (empty($userInfo->id)): ?>
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Ошибка</title>
</head>
<body style="color: #666; background-color: #d5d5d5; text-align: center; font-family: Consolas,monospace;">
Template::header('Ошибка');
Ошибка: персонаж <em><?= $login ?></em> не найден...
<p><a style="color: #99f" href="javascript:window.history.go(-1);">←назад</a></p>
</body>
</html>
<?php exit(); endif; ?>
<html lang="ru">
<head>
<title>Информация о <?= $userInfo->login ?></title>
<meta charset=UTF-8"/>
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<?php
Template::header('Информация о'.$userInfo->login);
try {
$userInfo->showUserInfo();
@ -38,6 +24,3 @@ try {
}
include_once 'views/presents-list.php';
?>
</body>
</html>