我正在尝试创建一个插件来为 Oxwall 框架制作 API 服务器。我是 ReSTLer 的新手,但经验丰富的 Oxwall 平台开发人员。
访问 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/* 路由有效)
OW::getRouter()->addRoute(new OW_Route('service', 'say/:cmd', "OXWALLAPI_CTRL_Api", 'index'));
所以现在,当我尝试访问 http://www.mysite.com/say/hello 时它得到上面的 404 错误。
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() {
}
}
说.php:
class Say {
function hello($to = 'world') {
return "Hello $to!";
}
function hi($to) {
return "Hi $to!";
}
}
Oxwall 有自己的 .htaccess 文件。我已将以下 .htaccess 放在插件文件夹中。
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
的同一文件夹中?
否则你应该在 Say.php 类中使用以下内容, 例如,如果你的 Say.php 在 Test/Say.php 在 Say.php 中写入
<?php
namespace Test;
use stdClass;
//..... the rest of your class
在 index.php 中你会写
$r->addClass('Test\Say');
- 您是否正确设置了
behat.yml
文件?
base_url 必须指向你的 index.php 路径
关于php - 所有 Url 的 ReSTLer 都出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21813776/