Restler总是返回错误404 [英] Restler always returning error 404 not found
问题描述
我似乎无法弄清楚这一点.
课程:
class Assets {
function getOne($id) {
$asset = DBO_Asset::getOneByPublicId($id);
return $asset->id;
}
}
index.php:
require_once 'restler/restler.php';
require_once 'API/Assets.php';
$rest = new Restler();
$rest->addAPIClass("Assets");
$rest->handle();
URL:
http://localhost/api/index.php/assets/getOne/8TWVTZAU
结果:
{
"error": {
"code": 404,
"message": "Not Found"
}
}
我不知道为什么要创建404,但是我按照说明进行操作,但仍然没有找到任何答案.有人可以帮我解决这个问题吗?
Restler使用get
,post
,put
,delete
作为方法前缀,以自动将它们映射到相应的HTTP方法/动词>
GET是默认的HTTP方法,因此,如果您不为上述方法加上前缀,它将被映射到GET方法
您的api当前正在映射到以下网址
http://localhost/api/index.php/assets/one/8TWVTZAU
如果在网址中包含getOne
对您很重要,请使用如下所示的@url
注释手动进行路由
class Assets
{
/**
* @url GET getOne/:id
* @url GET getOne
*/
function getOne($id)
{
$asset = DBO_Asset::getOneByPublicId($id);
return $asset->id;
}
}
I can't seem to figure this one out.
The class:
class Assets {
function getOne($id) {
$asset = DBO_Asset::getOneByPublicId($id);
return $asset->id;
}
}
The index.php:
require_once 'restler/restler.php';
require_once 'API/Assets.php';
$rest = new Restler();
$rest->addAPIClass("Assets");
$rest->handle();
The URL:
http://localhost/api/index.php/assets/getOne/8TWVTZAU
The result:
{
"error": {
"code": 404,
"message": "Not Found"
}
}
I have no idea why this is creating a 404, but I followed the instructions, and I am still not getting anywhere. Can someone please help me figure this out?
Restler is using get
, post
, put
, delete
as method prefixes to automatically map them to respective HTTP method/verb
GET is the default HTTP method, so if you dont prefix a method with any of the above, it will be mapped to GET method
Your api is currently mapping to the following url
http://localhost/api/index.php/assets/one/8TWVTZAU
If having getOne
in the url is important for you, use @url
comment as shown below to manually route that way
class Assets
{
/**
* @url GET getOne/:id
* @url GET getOne
*/
function getOne($id)
{
$asset = DBO_Asset::getOneByPublicId($id);
return $asset->id;
}
}
这篇关于Restler总是返回错误404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!