Restler拒绝实例化我的任何API类。它只是总是说它在Route上失败了,但却懒得提供任何其他有用的信息。我通过"restler/framework" : "3.0.0-RC6"
通过composer安装了Restler,然后创建了一个index.php,如下所示:
<?php
require __DIR__.'/../vendor/autoload.php';
use Luracast'Restler'Restler;
$r = new Restler();
$r->addAPIClass('Explorer');
$r->addAPIClass('Play');
$r->handle();
在与index.php完全相同的目录中,我创建了一个名为Play.php的文件,如下所示:
<?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');
}
当我调用http://.../api/play
时,我从来没有看到/tmp/scott文件被创建,我只是从Restler:得到了一般的失败响应
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:438 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
正如Luracast在评论中所指出的,我不得不编辑composer.json来添加这一节:
"autoload": {
"psr-0": {
"": "api"
}
}
然后运行composer dump-autoload