我想用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
而不是一个子文件夹,但仍得到相同的结果。
对不起,我仍然收到一个404 XML响应。我的目标是浏览到'http:// localhost/api/cars/search?term = red',它将调用search()函数,其中'$ term'参数等于'red',然后函数找到所有红色汽车记录并返回一个XML结果。 – Jake