【问题标题】:Restler 404 ErrorRestler 404 错误
【发布时间】:2013-12-01 12:03:32
【问题描述】:

我刚刚开始使用 Restler 创建一个 api 并拥有以下代码。

index.php

require_once '../vendor/restler.php';
use Luracast\Restler\Defaults;
use Luracast\Restler\Restler;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->setAPIVersion(1);
$r->setSupportedFormats('XmlFormat', 'JsonFormat');
$r->addAPIClass('Info', '');
$r->addAPIClass('Info');
$r->addAPIClass('getList');
$r->handle();

info.php

<?php
class Info {
    function index() {
        return "Version 1.0.0";
    }
}
?>

v1/getList.php

<?php
namespace v1;
use stdClass;
class getList
{
    function index()
    {
        return "hello";
    }
    function newest() {
        return "hello2";
    }
}

我正在 Windows 机器上使用 xampp 对其进行测试,并且 localhost/api/ 已映射到公用文件夹。 当我在浏览器中打开 localhost/api/ 时,它将按预期显示 Version 1.0。但是当我打开 infogetList 时,我从 apache 收到 404 错误。

我该如何解决? 非常感谢您的帮助

【问题讨论】:

    标签: php restler


    【解决方案1】:

    您应该将此添加到您的 /api/.htaccess 文件中:

    DirectoryIndex index.php
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^$ index.php [QSA,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2016-12-14
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      相关资源
      最近更新 更多