我刚刚开始用Restler创建一个api,并编写了相应的代码。
index.php
require_once '../vendor/restler.php';
use Luracast\Restler\Defaults;
use Luracast\Restler\Restler;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->setAPIVersion(1);
$r->setSupportedFormats('XmlFormat', 'JsonFormat');
$r->addAPIClass('Info', '');
$r->addAPIClass('Info');
$r->addAPIClass('getList');
$r->handle();info.php
<?php
class Info {
function index() {
return "Version 1.0.0";
}
}
?>v1/getList.php
<?php
namespace v1;
use stdClass;
class getList
{
function index()
{
return "hello";
}
function newest() {
return "hello2";
}
}我在windows机器上用xampp测试它,localhost/api/映射到公用文件夹。当我在浏览器中打开localhost/api/时,它将像预期的那样显示1.0版本。但是当我打开info或getList时,我会从apache那里得到一个404错误。
我怎么才能修好它?非常感谢你的帮助
发布于 2015-01-12 04:17:10
您应该将其添加到/api/.htaccess文件中:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>https://stackoverflow.com/questions/20311884
复制相似问题