【发布时间】:2019-09-29 20:56:14
【问题描述】:
我正在关注本教程https://symfony.com/doc/current/create_framework/front_controller.html 我有一个关于这个 php 代码的简单问题
// example.com/web/front.php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$request = Request::createFromGlobals();
$response = new Response();
$map = [
'/hello' => __DIR__.'/../src/pages/hello.php',
'/bye' => __DIR__.'/../src/pages/bye.php',
];
$path = $request->getPathInfo();
if (isset($map[$path])) {
ob_start();
include $map[$path];
$response->setContent(ob_get_clean());
} else {
$response->setStatusCode(404);
$response->setContent('Not Found');
}
$response->send();
代码在没有缓冲输出的情况下工作(没有使用 ob_ 调用 ...),所以我的问题是为什么?
【问题讨论】: