【问题标题】:404 Error with Restler for all Url所有 URL 的 Restler 出现 404 错误
【发布时间】:2014-02-16 16:13:05
【问题描述】:

我正在尝试创建一个插件来为 Oxwall 框架制作 API 服务器。我是 Restler 的新手,但在 Oxwall 平台方面经验丰富。

访问网址时出现以下错误。

{
  "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>

【问题讨论】:

    标签: php restler


    【解决方案1】:
    • Say.phpindex.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 路径

    【讨论】:

    • Api.php 和 Say.php 都在同一个文件夹中。文档没有说明 behat.yml 配置。请指导我在哪里可以找到该部分?
    • 我了解behat.yml配置仅用于单元测试。
    • 好吧,我可能错过了,但是在你的 api.php 中我也没有看到 require_once '../../../vendor/restler.php';
    • 我已经做到了。没有它,您将不会收到上述错误消息。
    • 我也有同样的问题。非常感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 2011-07-06
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 2012-08-16
    相关资源
    最近更新 更多