【问题标题】:Luracast restler 3 returns nothingLuracast restler 3 什么也没返回
【发布时间】: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


【解决方案1】:

好的,我刚刚想通了。我不得不将 .htaccess 移动到网站的根目录,然后将 RewriteRule 更改为拥有 rester/index.php 而不仅仅是 index.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 2018-10-10
    • 2014-03-07
    • 2016-03-14
    • 1970-01-01
    相关资源
    最近更新 更多