简体   繁体   English

Restler总是返回错误404

[英]Restler always returning error 404 not found

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: 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. 我不知道为什么要创建404,但是我按照说明进行了操作,但仍然无法解决任何问题。 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 Restler使用getpostputdelete作为方法前缀来自动将它们映射到相应的HTTP方法/动词

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 GET是默认的HTTP方法,因此,如果未在上述方法中添加任何前缀,它将被映射到GET方法

Your api is currently mapping to the following url 您的api当前正在映射到以下网址

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 如果在URL中使用getOne对您很重要,请使用如下所示的@url注释手动进行路由

class Assets
{
    /**
     * @url GET getOne/:id
     * @url GET getOne
     */
    function getOne($id)
    {
        $asset = DBO_Asset::getOneByPublicId($id);
        return $asset->id;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM