Files
coolcoth.com/app/Core/View.php
T
2026-08-08 15:53:53 +08:00

27 lines
718 B
PHP

<?php
namespace Core;
class View
{
public static function buffer(string $view, array $data = []): string
{
$file = BASE_PATH . '/app/Views/' . str_replace('.', '/', $view) . '.php';
if (!is_file($file)) {
throw new \Exception("视图不存在: $view");
}
ob_start();
extract($data, EXTR_SKIP);
include $file;
return ob_get_clean();
}
public static function make(string $view, array $data = [], ?string $layout = null): string
{
$content = self::buffer($view, $data);
if ($layout) {
return self::buffer($layout, array_merge($data, ['content' => $content]));
}
return $content;
}
}