Php Restler始终返回404:未找到

Php Restler始终返回404:未找到,php,.htaccess,restler,Php,.htaccess,Restler,我已经在我的本地服务器上安装了Restler,以便为我的项目测试和制作一些api Api请求通过http://localhost/myproject/api/ 问题是,每次我尝试提出请求时,都会出现以下错误: { "error": { "code": 404, "message": "Not Found" }, "debug": { "source": "Routes.php:383 at route stage",

我已经在我的本地服务器上安装了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

此外,我还尝试在
http://localhost/myproject/api/explorer
我一直收到错误:
404:找不到../resources.json
可能是因为我没有在项目的根文件夹中安装Restler。我应该如何在不同的子文件夹中安装Restler

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

class User {

    function data() {

        return "HELLO!";
    }
}
并在示例的
index.php
中添加了这一行:

$r->addAPIClass('User');
如果我尝试在
../\u 001\u helloworld/index.php/say/hello
上运行该示例,它会正常工作,但如果我尝试
\u 001\u helloworld/index.php/user/data
则不会


在这一点上,我已经失去了所有的希望,我真的需要帮助,因为我真的错过了一些东西,但真的猜不出是什么:(帮助!以下是如何调试和发现错误

  • 删除api.php中的名称空间。这不是必需的,会导致问题

  • 将资源管理器文件夹复制到
    /myproject/api
    文件夹,并将资源类添加为api类

    $restler->addApiClass('Resources'); //this produces the needed resources.json
    
  • 如果要添加具有名称空间的用户类,请确保在该名称空间下定义了该类,并使其可用于include语句或autoloader

  • 您可以创建
    /myproject/api/cache
    文件夹并使其可写。当您在生产模式下使用缓存刷新实例化restler时,它将在缓存文件夹中创建routes.php,其中列出所有路由信息

    $restler = new Restler(true,true); //production_mode, refresh
    

希望您能找到上面的问题所在

检查以确保您的功能是
公共的
而不是
私有的


实际上,我也遇到了同样的问题,只花了一个小时就解决了(facepalm)。

我遵循了前两个步骤,解决了问题。谢谢你,我非常感谢你的帮助:)我遇到了类似的问题。昨天一切正常,然后我开始收到Restler发来的404信息。我的所有web服务器配置均未更改。通过index.php工作,这样做或不使用index.php都会创建一个routes.php文件,在这两种情况下都是相同的;我使用了错误的URL。。Doh