2016-08-08 63 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