在 Slim 框架中如何读取一个文件的内容并输出呢?例如,下面的代码在一个普通的 PHP 应用程序中工作:
<?php
$data= json_decode(file_get_contents('C:\Users\Admin\Desktop\s1\vendor\me.json'), true);
print data["data"][0]["id"];
但是,如果我在 Slim 中编写以下代码,则没有任何结果:
use Slim\Http\Request;
use Slim\Http\Response;
require 'vendor/autoload.php';
$app->get('/test/', function(Request $reg, Response $res, $args = []){
$data= json_decode(file_get_contents('C:\Users\Admin\Desktop\s1\vendor\me.json'), true);
return $res->$data["data"][0]["id"];
});
告诉我我做错了什么?
如果您只想显示
$data["data"][0]["id"],请尝试