【发布时间】:2014-07-20 18:30:12
【问题描述】:
我在安装 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 吗?如果我给出的名称与 test 不同,我实际上会收到来自 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,但我希望将我所有的 RESTful API 内容都放在 restler 子目录中以保持干净。
【问题讨论】:
-
你能看到你的.htaccess
标签: restler