Restler php returning 404 for all results

纵然是瞬间 提交于 2019-12-12 01:34:52

问题


I've been looking into implementing a REST implementation for my API and came across Restler. I've installed Restler 2.0 and am using Apache and php > 5.3. My class is below:

Class Sample 
{
   function gettest()
   {
      return "This is a test";
   }
}

and the index.php is:

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
require_once('path/to/Sample.class.php');
spl_autoload_register('spl_autoload');
$r = new Restler();
$r->setSupportedFormats('JsonFormat');
$r->addAPIClass('Sample');
$r->handle();

and instead of using an .htaccess, I've included the following inside a

<Directory /path/to/REST_DIR>
    AllowOverride All
    Options +FollowSymLinks     
    DirectoryIndex index.php

RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Order deny,allow
    Allow from all

</Directory>

in my httpd.conf file (since it is supposed to be faster if you have access to edit it).

Whenever I try the following path:

http://www.myhost.com/REST_DIR/test/

I get:

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

Is there something I'm missing or some way to more thoroughly debug Restler to determine why it can't find the function gettest()?

Thanks in advance.

R


回答1:


as per the current configuration you can expect result from http://www.myhost.com/REST_DIR/sample/test

If you want the url to be http://www.myhost.com/REST_DIR/test instead, change index.php as follows

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
require_once('path/to/Sample.class.php');
spl_autoload_register('spl_autoload');
$r = new Restler();
$r->setSupportedFormats('JsonFormat'); //not needed JSON is the default
$r->addAPIClass('Sample',''); // note the empty string
$r->handle();


来源:https://stackoverflow.com/questions/14189033/restler-php-returning-404-for-all-results

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