Restler始终返回404:未找到

 LuoXR小堇_137 发布于 2023-02-11 18:57

我在本地服务器上安装了Restler来测试并为我的项目制作一些API.

Api请求通过http://localhost/myproject/api/.处理.

问题是每次我尝试发出请求时都会收到以下错误:

{
    "error": {
        "code": 404,
        "message": "Not Found"
    },
    "debug": {
        "source": "Routes.php:383 at route stage",
        "stages": {
            "success": [
                "get"
            ],
            "failure": [
                "route",
                "negotiate",
                "message"
            ]
        }
    }
}

这也是我的.htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api(.*)$ /myproject/api/api.php [QSA,L]

这就是api.php看起来像:

namespace myproject;

use Luracast\Restler\Restler;

require_once($_SERVER["DOCUMENT_ROOT"]."/myproject/resources/engine/settings.php");
require_once(Settings\Path\Absolute::$library."/restler/vendor/restler.php");

$restler = new Restler();
$restler->addAPIClass("myproject\\User");
$restler->handle();

我猜周围有一些误配,但我真的无法弄清楚出了什么问题.

(我也在Stackoverflow上尝试了一些解决方案,但它们似乎对我不起作用)

编辑:

我尝试使用以下路径到达示例 http://localhost/myproject/resources/engine/library/restler/public/examples并且它们正在工作,所以我想它与Restler本身的配置有关,因为它似乎无法工作http://localhost/myproject/api.

此外,我还尝试复制Restler Explorer http://localhost/myproject/api/explorer,我一直收到错误:404 : Not Found ../resources.json可能是因为我没有在我的项目的根文件夹中安装Restler.我怎么能在不同的子文件夹中安装Restler?

编辑2: 我刚刚将以下类移到示例001文件夹中:

class User {

    function data() {

        return "HELLO!";
    }
}

index.php在示例中添加了这一行:

$r->addAPIClass('User');

如果我尝试运行.../_001_helloworld/index.php/say/hello它的例子它没有问题,但如果我尝试_001_helloworld/index.php/user/data它不是.

在这一点上,我已经失去了所有的希望,我真的需要帮助'因为我真的错过了什么,但实在无法猜到:( 帮助!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有