【发布时间】:2017-10-25 15:31:24
【问题描述】:
我正在使用 slim php 路由器,但由于某种原因我收到此错误。
警告:file_get_contents(C:\xampp\htdocs/views/users.php?userId=3): 无法打开流:C:\xampp\htdocs\index.php 第 11 行没有错误
这是我的索引代码。
<?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();
?>
出于测试目的,我将其放在位于 views 文件夹中的 users.php 文件中
<?php
echo $_GET['userId'];
?>
你可以在https://github.com/slimphp/Slim找到这个php路由器
【问题讨论】:
标签: php file-get-contents router