Restler针对所有网址的404错误 [英] 404 Error with Restler for all Url
问题描述
我正在尝试创建一个插件,用于为Oxwall框架制作API服务器.我是Restler的新手,但经验丰富的Oxwall平台开发人员.
I am trying to create a plugin for making an API server for Oxwall framework. I am new to Restler but experienced developer for Oxwall platform.
访问网址时出现以下错误.
I get the below error when I access the url.
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:383 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
Oxwall具有自己的路由和MVC方法.下面是我如何定义路由的方法(cmd只是一个虚拟值,使Oxwall认为它对say/*路由有效)
Oxwall has its own Routing and MVC methods. Below is how I have defined the route (cmd is just a dummy value to make Oxwall consider it valid for say/* routes)
OW::getRouter()->addRoute(new OW_Route('service', 'say/:cmd', "OXWALLAPI_CTRL_Api", 'index'));
现在,当我尝试访问 http://www.mysite.com/say/hello 会出现上述404错误.
So now, when I try to access http://www.mysite.com/say/hello it get the above 404 error.
api.php:
use Luracast\Restler\Restler;
class OXWALLAPI_CTRL_Api extends OW_ActionController {
public function __construct() {
parent::__construct();
$r = new Restler();
$r->addAPIClass('Say');
$r->handle();
}
public function index() {
}
}
Say.php:
class Say {
function hello($to = 'world') {
return "Hello $to!";
}
function hi($to) {
return "Hi $to!";
}
}
Oxwall具有自己的.htaccess文件.我已将以下.htaccess放在插件文件夹中.
Oxwall has its own .htaccess file. I have placed the below .htaccess in the plugin folder.
Options -MultiViews
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>
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
推荐答案
-
Say.php
是否在index.php
的同一文件夹中? - Is
Say.php
in the same folder ofindex.php
?
否则,您应该在Say.php类中使用以下内容, 例如,如果您的Say.php在Test/Say.php中 在Say.php中写
Otherwise you should use the following in Say.php class, if for instance your Say.php is in Test/Say.php In Say.php write
<?php
namespace Test;
use stdClass;
//..... the rest of your class
在index.php中,您将编写
In index.php you'll write
$r->addClass('Test\Say');
- 您是否正确设置了
behat.yml
文件? - Did you properly set the
behat.yml
file?
base_url必须指向您的index.php路径
base_url must point to your index.php path
这篇关于Restler针对所有网址的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!