我在安装restler时弄乱了一些东西。在我的网站的子文件夹中,我想要REST api,我把restler附带的供应商目录(除去其他所有内容),然后我在同一级别创建了一个index.php文件:
<?php
require_once 'vendor/restler.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Test');
$r->handle();
?>
此级别的.htaccess文件只是Restler文档中的文件而没有更改。然后我创建了一个简单的Test.php文件,它只返回一个JSON数组:
<?php
class Test {
function index() {
return [1, 2, 3];
}
}
?>
现在查询该URL会返回nada:
curl -i https://.../dts/restler/Test
HTTP/1.1 200 OK
Date: Sun, 20 Jul 2014 18:20:40 GMT
Server: Apache/2.2.26 (Unix) DAV/2 PHP/5.4.24 mod_ssl/2.2.26 OpenSSL/0.9.8y
X-Powered-By: PHP/5.4.24
MS-Author-Via: DAV
Vary: User-Agent
Content-Length: 0
Content-Type: text/html; charset=UTF-8
注意“X-Powered-By”是如何只是普通的PHP?如果我提供的名称不同于测试,我实际上从Restler收到错误:
curl -i https://.../dts/restler/Invalid
HTTP/1.1 404 Not Found
Date: Sun, 20 Jul 2014 18:22:18 GMT
Server: Apache/2.2.26 (Unix) DAV/2 PHP/5.4.24 mod_ssl/2.2.26 OpenSSL/0.9.8y
X-Powered-By: Luracast Restler v3.0.0rc5
Vary: Accept,User-Agent
Cache-Control: no-cache, must-revalidate
Expires: 0
Content-Language: en
MS-Author-Via: DAV
Content-Length: 360
Content-Type: application/json; charset=utf-8
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:436 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
所以我的网站的根目录是... / dts,但我希望在restler子目录中拥有所有我的restful API,以保持干净。
答案 0 :(得分:0)