2016-08-08 68 views
2

我想用xampp 5.6.23在Windows上设置开发环境。Restler 404 error Routes.php:431 with xampp

我有一个API我想建立与Restler 3.0.0这样我就可以浏览到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并设置AllowOverride All无处不在我可以在httpd.conf中找到它。我也尝试将我的一切移到htdocs而不是一个子文件夹,但仍得到相同的结果。

回答

0

既然您没有index()功能,但只有search()函数在您的类cars中,您需要访问URL /cars/search/term

或者你是否想要实现其他目的?

+0

对不起,我仍然收到一个404 XML响应。我的目标是浏览到'http:// localhost/api/cars/search?term = red',它将调用search()函数,其中'$ term'参数等于'red',然后函数找到所有红色汽车记录并返回一个XML结果。 – Jake