简体   繁体   中英

Restler 2: When calling index.php, display error 404

I am new to Restler 2.0 I trying to create an API, http://exampe.com/api/index.php/lbs/hello/123456 and it return success result But when i put http://exampe.com/api/index.php/lbs/getloc/123456 , it return fail. Anyone know what does it happen?

Result:

{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

Below are the code:

index.php

require_once 'restler/restler.php';
require_once 'classes/lbs.php';

$r = new Restler();
$r->addAPIClass('LBS');
$r->addAPIClass('Say');
$r->handle();

lbs.php

class LBS {
    function getloc($to) {
        return $to;
    }

    function hello($to) {
        return $to;
        }
}

You need to include the file containing the class Say you added via addAPIClass method. Your index file should be something like below

require_once 'restler/restler.php';
require_once 'classes/lbs.php';
require_once 'classes/say.php';

$r = new Restler();
$r->addAPIClass('LBS');
$r->addAPIClass('Say');
$r->handle();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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