简体   繁体   English

Restler PHP为所有结果返回404

[英]Restler php returning 404 for all results

I've been looking into implementing a REST implementation for my API and came across Restler. 我一直在研究为我的API实现REST实现,并且遇到了Restler。 I've installed Restler 2.0 and am using Apache and php > 5.3. 我已经安装了Restler 2.0,并且正在使用Apache和php> 5.3。 My class is below: 我的课程如下:

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

and the index.php is: 并且index.php是:

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 而不是使用.htaccess,我将以下内容包含在

<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). 在我的httpd.conf文件中(因为如果可以编辑它,它应该会更快)。

Whenever I try the following path: 每当我尝试以下路径时:

http://www.myhost.com/REST_DIR/test/ 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()? 是否有我缺少的东西,或者有什么方法可以更彻底地调试Restler,以确定为什么找不到功能gettest()?

Thanks in advance. 提前致谢。

R [R

as per the current configuration you can expect result from http://www.myhost.com/REST_DIR/sample/test 根据当前配置,您可以期望从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 如果您希望将该网址改为http://www.myhost.com/REST_DIR/test ,请按如下所示更改index.php

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();

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

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