我一直在研究为我的API实现REST实现,并遇到了Restler。我已经安装了Restler 2.0,并且正在使用Apache和php > 5.3。我的类如下:
Class Sample
{
function gettest()
{
return "This is a test";
}
}index.php是:
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
require_once('path/to/Sample.class.php');
spl_autoload_register('spl_autoload');
$r = new Restler();
$r->setSupportedFormats('JsonFormat');
$r->addAPIClass('Sample');
$r->handle();我没有使用.htaccess,而是在一个
<Directory /path/to/REST_DIR>
AllowOverride All
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Order deny,allow
Allow from all
</Directory>在我的httpd.conf文件中(因为如果你有权编辑它,它应该会更快)。
每当我尝试以下路径时:
http://www.myhost.com/REST_DIR/test/
我得到了:
{
"error": {
"code": 404,
"message": "Not Found"
}
}我是否遗漏了什么,或者有什么方法可以更彻底地调试Restler,以确定它找不到gettest()函数的原因?
提前谢谢。
R
发布于 2013-01-07 16:16:14
根据当前配置,您可以预期来自http://www.myhost.com/REST_DIR/sample/test的结果
如果您希望url改为http://www.myhost.com/REST_DIR/test,请按如下方式更改index.php
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
require_once('path/to/Sample.class.php');
spl_autoload_register('spl_autoload');
$r = new Restler();
$r->setSupportedFormats('JsonFormat'); //not needed JSON is the default
$r->addAPIClass('Sample',''); // note the empty string
$r->handle();https://stackoverflow.com/questions/14189033
复制相似问题