Restler PHP为所有结果返回404 [英] Restler php returning 404 for all results
问题描述
我一直在研究为我的API实现REST实现,并且遇到了Restler.我已经安装了Restler 2.0,并且正在使用Apache和php> 5.3.我的课在下面:
I've been looking into implementing a REST implementation for my API and came across Restler. I've installed Restler 2.0 and am using Apache and php > 5.3. My class is below:
Class Sample
{
function gettest()
{
return "This is a test";
}
}
而index.php是:
and the index.php is:
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,我将以下内容包含在
and instead of using an .htaccess, I've included the following inside a
<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文件中(因为如果可以编辑它,它应该会更快).
in my httpd.conf file (since it is supposed to be faster if you have access to edit it).
每当我尝试以下路径时:
Whenever I try the following path:
http://www.myhost.com/REST_DIR/test/
我得到:
{
"error": {
"code": 404,
"message": "Not Found"
}
}
我是否缺少某些东西,或者有什么方法可以更彻底地调试Restler,以确定为什么找不到函数gettest()?
Is there something I'm missing or some way to more thoroughly debug Restler to determine why it can't find the function gettest()?
谢谢.
R
推荐答案
根据当前配置,您可以期望 http://www.myhost.com/REST_DIR/sample/test
as per the current configuration you can expect result from http://www.myhost.com/REST_DIR/sample/test
如果您希望url为 http://www.myhost.com/REST_DIR/test相反,如下更改index.php
If you want the url to be http://www.myhost.com/REST_DIR/test instead, change index.php as follows
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();
这篇关于Restler PHP为所有结果返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!