Reputation: 1227
I am trying to set up a development environment on Windows with xampp 5.6.23.
I have an API I want to set up with Restler 3.0.0 so that I can browse to http://localhost/api/cars/search?term=red
to call the search($term)
function in the C:\xampp\htdocs\api\cars.php
file:
<?php
class cars{
public function search($term) {
// do search...
return $result;
}
}
I also have a C:\xampp\htdocs\api\index.php
set up with:
<?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
and 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>
But if I go to any URL (/
or /cars
) I get a 404 error:
<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>
I have tried multiple answers from SO but none have worked in my instance. I have uncommented LoadModule rewrite_module modules/mod_rewrite.so
and set AllowOverride All
everywhere I could find it in httpd.conf
. I have also tried moving my everything to htdocs
instead of a sub folder but still get the same result.
Upvotes: 2
Views: 476
Reputation: 119
Since you don't have an index()
function but only a search()
function in your class cars
, you need to access the URL /cars/search/term
.
Or are you trying to achieve something else?
Upvotes: 0