我已经在我的本地服务器上安装了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,并且一直收到错误: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,它就没有问题。
在这一点上,我失去了所有的希望,我真的需要帮助,因为我真的错过了什么,但我真的猜不出是什么:( 帮助!
发布于 2013-12-11 03:27:26
以下是调试和发现错误的方法,
/myproject/api文件夹,并将参考资料类添加为api类
$restler->addApiClass('Resources');//这将生成所需的resources.json/myproject/api/cache文件夹并使其可写。当您在生产模式下实例化restler时,如下图所示,它将在缓存文件夹中创建routes.php,其中列出了所有路由信息
$restler = new (真,真);//产品_模式,刷新希望你能发现上面的错误。
发布于 2020-01-09 22:43:49
检查以确保您的函数是public而不是private。
实际上,我也遇到了同样的问题,我花了一个小时来解决这个问题(facepalm)。
https://stackoverflow.com/questions/20488815
复制相似问题