2026-09-30 00:49:53 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 视图渲染。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 流程:render() 把数据展开 → 把「本页模板文件路径 / 当前页标识 / 标题」交给
|
|
|
|
|
|
* layout.php → layout 在正文位置 require 本页模板。
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
|
|
final class View
|
|
|
|
|
|
{
|
|
|
|
|
|
public static function render(string $tpl, array $data = [], string $page = ''): void
|
|
|
|
|
|
{
|
|
|
|
|
|
$file = dirname(__DIR__) . '/templates/' . $tpl . '.php';
|
|
|
|
|
|
if (!is_file($file)) {
|
|
|
|
|
|
throw new \RuntimeException('模板不存在:' . $tpl);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$tplFile = $file;
|
|
|
|
|
|
$pageKey = $page ?: $tpl;
|
|
|
|
|
|
$pageTitle = $data['title'] ?? '家书';
|
|
|
|
|
|
$extraHead = $data['extraHead'] ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
extract($data, EXTR_SKIP);
|
|
|
|
|
|
require dirname(__DIR__) . '/templates/layout.php';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-30 08:13:07 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 独立的整页(登录、安装、错误),不套顶栏 —— 但**仍然要是一份完整 HTML**。
|
|
|
|
|
|
*
|
|
|
|
|
|
* ⚠️ 曾经这里直接 require $file,输出里没有 doctype / head / CSS,
|
|
|
|
|
|
* 浏览器拿默认样式渲染,登录页看起来就像「完全没样式」。
|
|
|
|
|
|
* 现在统一套一层 layout-bare.php(无顶栏的最小骨架)。
|
|
|
|
|
|
*/
|
2026-09-30 00:49:53 +08:00
|
|
|
|
public static function renderBare(string $tpl, array $data = []): void
|
|
|
|
|
|
{
|
|
|
|
|
|
$file = dirname(__DIR__) . '/templates/' . $tpl . '.php';
|
|
|
|
|
|
if (!is_file($file)) {
|
|
|
|
|
|
throw new \RuntimeException('模板不存在:' . $tpl);
|
|
|
|
|
|
}
|
2026-09-30 08:13:07 +08:00
|
|
|
|
$tplFile = $file;
|
2026-09-30 00:49:53 +08:00
|
|
|
|
$pageTitle = $data['title'] ?? '家书';
|
2026-09-30 08:13:07 +08:00
|
|
|
|
$extraHead = $data['extraHead'] ?? '';
|
2026-09-30 00:49:53 +08:00
|
|
|
|
extract($data, EXTR_SKIP);
|
2026-09-30 08:13:07 +08:00
|
|
|
|
require dirname(__DIR__) . '/templates/layout-bare.php';
|
2026-09-30 00:49:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|