我正在使用slim php路由器,出于某种原因,我收到此错误。未能打开流:第11行的C: xampp htdocs index.php中没有错误
警告:的file_get_contents(C:\ XAMPP \ htdocs中/视图/ users.php用户id = 3):未能打开流:在C无误差:\ XAMPP \ htdocs中\上线11
的index.php
这里是我的索引代码。
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require dirname(__FILE__) . '/vendor/autoload.php';
$app = new \Slim\App;
$app->get('/users/{userId}', function ($request, $response, $args) {
if (!ctype_alnum($args['userId'])) {
$args['userId'] = '0';
}
$body = file_get_contents(dirname(__FILE__) . "/views/users.php?userId={$args['userId']}");
return $response->write($body);
});
$app->run();
?>
出于测试目的,我把这个在位于视图文件夹中的文件users.php
<?php
echo $_GET['userId'];
?>
你可以找到https://github.com/slimphp/Slim
你有路过的用户ID的用户页面,以便它可以请求ID –
时遗憾的响应晚了,我摔了个睡眠 –
这将只返回显示正确的用户替代PHP源代码,它不会运行脚本。 – Barmar