安装新版本4.12后,我在Slim 4上仍然出现此错误

问题描述 投票:0回答:1

[在安装新的Slim 4框架后,我仍然收到此错误Slim Application Error

我尝试切换回旧版slim,但我一直得到同样的东西。

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

/**
 * Instantiate App
 *
 * In order for the factory to work you need to ensure you have installed
 * a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
 * ServerRequest creator (included with Slim PSR-7)
 */
$app = AppFactory::create();

// Add Routing Middleware
$app->addRoutingMiddleware();

/*
 * Add Error Handling Middleware
 *
 * @param bool $displayErrorDetails -> Should be set to false in production
 * @param bool $logErrors -> Parameter is passed to the default ErrorHandler
 * @param bool $logErrorDetails -> Display error details in error log
 * which can be replaced by a callable of your choice.

 * Note: This middleware should be added last. It will not handle any exceptions/errors
 * for middleware added after it.
 */
$errorMiddleware = $app->addErrorMiddleware(true, true, true);

// Define app routes
$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;
});

// Run app
$app->run();

输出:

Slim Application Error
The application could not run because of the following error:

Details

Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 91

Trace:

#0 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(57): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner))
#2 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(89): class@anonymous->handle(Object(Slim\Psr7\Request))
#3 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#4 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): class@anonymous->handle(Object(Slim\Psr7\Request))

#5 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/App.php(206): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#6 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/App.php(190): Slim\App->handle(Object(Slim\Psr7\Request))
#7 /opt/lampp/htdocs/MyocappAPI/public/index.php(41): Slim\App->run()
#8 {main}
slim slim-4
1个回答
0
投票

将精简版降级到3。*

© www.soinside.com 2019 - 2024. All rights reserved.