我在本地服务器上安装了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
它不是.
在这一点上,我已经失去了所有的希望,我真的需要帮助'因为我真的错过了什么,但实在无法猜到:( 帮助!