【问题标题】:Restler php returning 404 for all resultsRestler php为所有结果返回404
【发布时间】:2012-12-20 18:34:36
【问题描述】:

我一直在研究为我的 API 实现 REST 并遇到了 Restler。我已经安装了 Restler 2.0 并且正在使用 Apache 和 php > 5.3。我的课在下面:

Class Sample 
{
   function gettest()
   {
      return "This is a 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');
$r->addAPIClass('Sample');
$r->handle();

我没有使用 .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>

在我的 httpd.conf 文件中(因为如果您有权编辑它应该会更快)。

每当我尝试以下路径时:

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

我明白了:

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

有什么我遗漏的东西,或者有什么方法可以更彻底地调试 Restler 以确定它为什么找不到函数 gettest()?

提前致谢。

R

【问题讨论】:

    标签: php rest http-status-code-404 restler


    【解决方案1】:

    根据当前配置,您可以从http://www.myhost.com/REST_DIR/sample/test 获得结果

    如果您希望 url 改为 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();
    

    【讨论】:

    • 感谢 Luracast - 我很抱歉回想起来这是一个愚蠢的问题 - 这是漫长的一天。感谢您对这个库的支持和开发 - 等不及 3.0!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    相关资源
    最近更新 更多