Restler always returning error 404 not found

好久不见. 提交于 2019-12-13 05:56:15

问题


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?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/12046207/restler-always-returning-error-404-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!