Fatal error: Uncaught Slim\Exception\HttpNotFoundException in Slim 4.7
Fatal error: Uncaught Slim\Exception\HttpNotFoundException in Slim 4.7
我正在尝试启动我的应用程序,但每次我在浏览器中打开时 http://localhost/
它都会给我这个错误:
/* namespace handles; use connection\Sql; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; $app = AppFactory::create(); $sql = new Sql(); $stmt = $sql -> comand( "SELECT * FROM substancias" ); $app->get('/hello/{name}', function (Request $request, Response $response, $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); return $response; }); $app->run(); var_dump($stmt); */
Fatal error: Uncaught Slim\Exception\HttpNotFoundException: Not found. in C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php:91 Stack trace: #0 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Routing\RouteRunner.php(72): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): Slim\Routing\RouteRunner->handle(Object(Slim\Psr7\Request))
#2 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\App.php(215): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#3 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\App.php(199): Slim\App->handle(Object(Slim\Psr7\Request))
#4 C:\Users\mathe\Desktop\conscious\backend\vendor\src\index.php(24): Slim\App->run()
#5 {main} thrown in C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php on line 91
我已经尝试 setBasePath
,但还是不行,有人可以帮忙吗?谢谢
Index.php C:\Users\mathe\Desktop\conscious\backend\vendor\src
内的代码:
<?php
namespace src;
header("Access-Control-Allow-Headers: *");
require("../autoload.php");
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use handles\userhandle;
$ei = "test";
$app = AppFactory::create();
$app->setBasePath('/myapp');
$user = new userhandle();
$app->get('/aki' , function(Request $request, Response $response){
global $user;
$user->VER($request, $response);
});
$app->run();
var_dump($ei);
?>
userhandle.php 里面 C:\Users\mathe\Desktop\conscious\backend\vendor\src\handles
:
<?php
namespace handles;
header("Access-Control-Allow-Headers: *");
require("../../../vendor/autoload.php");
use connection\Sql;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class userhandle {
private $sql;
public function VER(Request $request, Response $response){
$this->sql = new sql();
$stmt = $this->sql -> comand(
"SELECT * FROM substancias"
);
$response->getBody()->write($stmt);
return $response;
}
}
?>
之后 -> $app = AppFactory::create();
添加 -> $app->addErrorMiddleware(true, true, true);
add -> $app->setBasePath("/project_folder/api");
//index.php所在文件夹
这是我的 .htaccess(也位于 api 文件夹)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
我正在尝试启动我的应用程序,但每次我在浏览器中打开时 http://localhost/
它都会给我这个错误:
/* namespace handles; use connection\Sql; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; $app = AppFactory::create(); $sql = new Sql(); $stmt = $sql -> comand( "SELECT * FROM substancias" ); $app->get('/hello/{name}', function (Request $request, Response $response, $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); return $response; }); $app->run(); var_dump($stmt); */
Fatal error: Uncaught Slim\Exception\HttpNotFoundException: Not found. in C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php:91 Stack trace: #0 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Routing\RouteRunner.php(72): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): Slim\Routing\RouteRunner->handle(Object(Slim\Psr7\Request))
#2 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\App.php(215): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#3 C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\App.php(199): Slim\App->handle(Object(Slim\Psr7\Request))
#4 C:\Users\mathe\Desktop\conscious\backend\vendor\src\index.php(24): Slim\App->run()
#5 {main} thrown in C:\Users\mathe\Desktop\conscious\backend\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php on line 91
我已经尝试 setBasePath
,但还是不行,有人可以帮忙吗?谢谢
Index.php C:\Users\mathe\Desktop\conscious\backend\vendor\src
内的代码:
<?php
namespace src;
header("Access-Control-Allow-Headers: *");
require("../autoload.php");
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use handles\userhandle;
$ei = "test";
$app = AppFactory::create();
$app->setBasePath('/myapp');
$user = new userhandle();
$app->get('/aki' , function(Request $request, Response $response){
global $user;
$user->VER($request, $response);
});
$app->run();
var_dump($ei);
?>
userhandle.php 里面 C:\Users\mathe\Desktop\conscious\backend\vendor\src\handles
:
<?php
namespace handles;
header("Access-Control-Allow-Headers: *");
require("../../../vendor/autoload.php");
use connection\Sql;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class userhandle {
private $sql;
public function VER(Request $request, Response $response){
$this->sql = new sql();
$stmt = $this->sql -> comand(
"SELECT * FROM substancias"
);
$response->getBody()->write($stmt);
return $response;
}
}
?>
之后 -> $app = AppFactory::create();
添加 -> $app->addErrorMiddleware(true, true, true);
add -> $app->setBasePath("/project_folder/api");
//index.php所在文件夹
这是我的 .htaccess(也位于 api 文件夹)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]