【问题标题】:Restler 404 error Routes.php:431 with xamppRestler 404 错误 Routes.php:431 与 xampp
【发布时间】:2016-12-14 20:44:40
【问题描述】:

我正在尝试使用 xampp 5.6.23 在 Windows 上设置开发环境。

我想用 Restler 3.0.0 设置一个 API,以便我可以浏览到 http://localhost/api/cars/search?term=red 以调用 C:\xampp\htdocs\api\cars.php 文件中的 search($term) 函数:

<?php
class cars{
    public function search($term) {
    // do search...
    return $result;
    }
}

我还有一个C:\xampp\htdocs\api\index.php 设置:

<?php
require_once 'vendor/autoload.php';
require_once 'vendor/luracast/restler/vendor/restler.php';
use Luracast\Restler\Restler;

Defaults::$crossOriginResourceSharing = true;

$r = new Luracast\Restler\Restler();
$r->setCompatibilityMode('2');
$r->setSupportedFormats('JsonFormat', 'XmlFormat', 'JsFormat');
Luracast\Restler\Format\JsonFormat::$unEscapedUnicode = false;

$r->addAPIClass('cars');

$r->addAPIClass('Luracast\\Restler\\Resources');

$r->handle(); //serve the response

C:\xampp\htdocs\api\.htdocs:

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

但如果我访问任何 URL(//cars),我会收到 404 错误:

<response>
 <error>
  <code>404</code>
  <message>Not Found</message>
 </error>
 <debug>
  <source>Routes.php:431 at route stage</source>
  <stages>
   <success>get</success>
   <failure>route</failure>
   <failure>negotiate</failure>
   <failure>message</failure>
  </stages>
 </debug>
</response>

我尝试了 SO 的多个答案,但在我的实例中没有一个有效。我取消了LoadModule rewrite_module modules/mod_rewrite.so 的注释,并在httpd.conf 的任何地方设置了AllowOverride All。我还尝试将我的所有内容移动到 htdocs 而不是子文件夹,但仍然得到相同的结果。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite restler


    【解决方案1】:

    由于您的类cars 中没有index() 函数而只有search() 函数,因此您需要访问URL /cars/search/term

    或者你想实现别的目标?

    【讨论】:

    • 抱歉,我仍然收到 404 XML 响应。我的目标是浏览到http://localhost/api/cars/search?term=red,它将调用$term 参数等于redsearch() 函数,然后该函数找到所有红色汽车记录并返回一个XML 结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2012-08-16
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    相关资源
    最近更新 更多