Проблема с Slim - HttpNotFoundException - PullRequest
0 голосов
/ 26 мая 2020

Я использую slim 4 и не уверен, что здесь не так.

index. php

    <?php
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    use Slim\Factory\AppFactory;
    
    require __DIR__ . '/../vendor/autoload.php';
    
    $app = AppFactory::create();
    
    
    $app->addRoutingMiddleware();
    $errorMiddleware = $app->addErrorMiddleware(true, true, true);
    $app->setBasePath("/MyApi/public/index.php");
    
    $app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
        $name = $args['name'];
        $response->getBody()->write("Hello, $name");
        return $response;
    });
    
    $app->run();

Подробности

Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 91

След

#0 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(57): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner))
#2 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(89): class@anonymous->handle(Object(Slim\Psr7\Request))
#3 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#4 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): class@anonymous->handle(Object(Slim\Psr7\Request))
#5 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/App.php(208): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#6 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/App.php(192): Slim\App->handle(Object(Slim\Psr7\Request))
#7 /Applications/XAMPP/xamppfiles/htdocs/MyApi/public/index.php(21): Slim\App->run()
#8 {main}
...