我正在尝试使用League / route PHP软件包来管理友好的路线:
https://route.thephpleague.com/4.x/usage/
到目前为止,我所做的就是将它们的“ Hello world”示例复制到我的index.php文件中:
<?php declare(strict_types=1);
require './vendor/autoload.php';
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
);
$router = new League\Route\Router;
// map a route
$router->map('GET', '/asdf', function (ServerRequestInterface $request) : ResponseInterface {
$response = new Zend\Diactoros\Response;
$response->getBody()->write('<h1>Hello, World!</h1>');
return $response;
});
$response = $router->dispatch($request);
// send the response to the browser
(new Zend\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response);
然后出现以下错误:
严重错误:未捕获的League \ Route \ Http \ Exception \ NotFoundException:在/var/www/html/gangsters_php/vendor/league/route/src/Dispatcher.php:124中找不到堆栈跟踪:#0 / var / www / html / gangsters_php / vendor / league / route / src / Dispatcher.php(36):League \ Route \ Dispatcher-> setNotFoundDecoratorMiddleware()#1 / var / www / html / gangsters_php / vendor / league / route / src / Router.php(112):League \ Route \ Dispatcher-> dispatchRequest(Object(Zend \ Diactoros \ ServerRequest))#2 /var/www/html/gangsters_php/index.php(21):League \ Route \ Router-> dispatch(Object(Zend \ Diactoros \ ServerRequest))#3 {main}在第124行的/var/www/html/gangsters_php/vendor/league/route/src/Dispatcher.php中抛出