【发布时间】:2013-12-27 15:16:04
【问题描述】:
我已经在我的本地服务器上安装了 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 中复制 Restler 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,它不会。
在这一点上,我已经失去了所有希望,我真的需要帮助,因为我确实错过了一些东西,但我真的猜不出是什么:( 帮助!
【问题讨论】: