seeren/controller

管理 http 消息的动作

4.1.0 2022-01-08 14:09 UTC

This package is auto-updated.

Last update: 2024-09-08 20:19:26 UTC


README

Build Require Coverage Download CodacyVersion

管理 http 消息的动作

安装

composer require seeren/controller

Seeren\Controller\JsonController

检索 JSON 格式的 PSR-7 响应

use Seeren\Controller\JsonController;

$controller = new JsonController();
$response = $controller->render(['foo' => 'bar']);

Seeren\Controller\HTMLController

检索 HTML 格式的 PSR-7 响应

use Seeren\Controller\HTMLController;

$controller = new HTMLController();
$response = $controller->render('template.html.php', [
    'title' => 'Hello World'
]);

默认情况下,模板文件夹位于 /templates,构造时可以指定包含路径

project/
└─ templates/

模板使用 PHP 语法,默认情况下值会被清理

<h1><?= $title ?></h1>

许可证

本项目受 MIT 许可证许可,详情请见 LICENSE