Restler 3.0.0rc6。
我在本地开发环境中在Restler中设置了一个简单的REST服务。当我搬到测试服务器时,Restler找不到任何路由。
我通过远程主机让项目与git同步。我刚刚将最新的本地更改提取到我的测试服务器,因此文件夹设置应该没问题。
错误出现在方法Routes.php
中的find
第362行,该方法试图找到与请求的网址匹配的api方法。该文件中的说明:
$p = Util::nestedValue(static::$routes, "v$version");
返回$p = NULL
。调用中的参数值为:
static::$routes is an empty array - array().
$version is int(1)
在此代码之后,条件会触发$p = NULL
的异常。
我已经尝试过mininum Hello world示例并且始终遇到同样的问题。
由于应用程序在我的本地服务器上工作正常,我可以想到我的测试服务器中的一些配置会弄乱一切,但无法跟踪它是什么。由于我不知道从哪里开始,我只是包含一些信息,以防它有用。
我包含我的文件夹配置:
html/api/ -> index.php and custom class files
html/api/data-base -> database acces files
html/api/vendor -> Restler
我的index.php文件
<?php
require_once 'vendor/restler.php';
require_once('data-base/data-base-pdo.php');
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Individuals');
$r->addAPIClass('Injuries');
$r->addAPIClass('Measurements');
$r->addAPIClass('Sessions');
$r->addAPIClass('Reports');
$r->handle();
我的一个班级文件:
<?php
use Luracast\Restler\RestException;
class Individuals
{
public $db;
public function __construct() {
$this->db = DataBase::getInstance();
}
public function index() {
return $this->db->individualsSelect();
}
public function get($id) {
try {
return $this->db->individualsSelectOne($id);
} catch(mysqli_exception $e) {
throw new RestException(500, $e->getMessage(), array(), $e);
} catch(InvalidArgumentException $e) {
throw new RestException(400, $e->getMessage(), array(), $e);
}
}
public function put($id, $request_data) {
try {
return $this->db->individualsUpdate($id, $request_data);
} catch(mysqli_exception $e) {
throw new RestException(500, $e->getMessage(), array(), $e);
} catch(InvalidArgumentException $e) {
throw new RestException(400, $e->getMessage(), array(), $e);
}
}
/**
* @url GET {individuals_id}/injuries
*/
public function injuries($individuals_id) {
try {
return $this->db->injuriesSelectByIndividual($individuals_id);
} catch(mysqli_exception $e) {
throw new RestException(500, $e->getMessage(), array(), $e);
} catch(InvalidArgumentException $e) {
throw new RestException(400, $e->getMessage(), array(), $e);
}
}
/**
* @url GET {individuals_id}/measurements
*/
public function measurements($individuals_id) {
try {
return $this->db->measurementsSelectByIndividual($individuals_id);
} catch(mysqli_exception $e) {
throw new RestException(500, $e->getMessage(), array(), $e);
} catch(InvalidArgumentException $e) {
throw new RestException(400, $e->getMessage(), array(), $e);
}
}
/**
* @url GET {individuals_id}/sessions
*/
public function sessions($individuals_id) {
try {
return $this->db->sessionsSelectByIndividual($individuals_id);
} catch(mysqli_exception $e) {
throw new RestException(500, $e->getMessage(), array(), $e);
} catch(InvalidArgumentException $e) {
throw new RestException(400, $e->getMessage(), array(), $e);
}
}
}
答案 0 :(得分:0)
问题在于文件名和类名中的Case。我的所有条目都以大写字母Individuals
开头,但文件都是小写,如individuals.php
。我的开发环境不区分大小写,所以restler可以找到我的clases的文件,但是一旦我在我的测试服务器中部署,一切都被打破了。