404 Error with Restler for all Url

喜欢而已 提交于 2020-01-01 17:06:08

问题


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 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'));

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

回答1:


  • Is Say.php in the same folder of index.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

In index.php you'll write

$r->addClass('Test\Say');
  • Did you properly set the behat.yml file?

base_url must point to your index.php path



来源:https://stackoverflow.com/questions/21813776/404-error-with-restler-for-all-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!