问题描述:

Restler is refusing to instantiate any of my API classes. It's just always saying it fails on Route, but doesn't bother to provide any other useful information. I installed Restler via composer via "restler/framework" : "3.0.0-RC6" and then created an index.php that looks like this:

<?php

require __DIR__.'/../vendor/autoload.php';

use Luracast\Restler\Restler;

$r = new Restler();

$r->addAPIClass('Explorer');

$r->addAPIClass('Play');

$r->handle();

In the exact same directory as the index.php I've created a file called Play.php that looks like so:

<?php

public class Play

{

public function __construct() {

error_log("I called the constructor!\n", 3, '/tmp/scott');

}

public function index() {

error_log("I called the index\n", 3, '/tmp/scott');

}

When I call http://.../api/play I never see the /tmp/scott file created, and I just get the generic failure response from Restler:

{

"error": {

"code": 404,

"message": "Not Found"

},

"debug": {

"source": "Routes.php:438 at route stage",

"stages": {

"success": [

"get"

],

"failure": [

"route",

"negotiate",

"message"

]

}

}

}

网友答案:

As Luracast noted in the comments, I had to edit the composer.json to add this stanza:

"autoload": {
    "psr-0": {
        "": "api"
    }
}

and then run composer dump-autoload

相关阅读:
Top