我在 Restler PHP REST Framework v3 中实现智能 url 路由时遇到了一些问题。基本上看起来 Restler 似乎忽略了我的评论。我在这里附上了我的 index.php 和 tests.inc.php 文件。正在发生的事情,即使是 PHPDoc 注释,似乎restler 忽略它们并且只响应默认的“测试”调用而不是“some/new/route”,正如我所期望的那样,基于提供的路由示例框架。
索引.php
<?php
$root_dir = $_SERVER['DOCUMENT_ROOT'];
$base_dir = getcwd();
$include = "{$base_dir}/include";
require_once("{$include}/config.inc.php");
require_once("{$include}/library-general.inc.php");
//include restler library
$restler_dir = "{$root_dir}/restler/{$settings['restler_version_string']}";
require_once("{$restler_dir}/restler.php");
//restler configuration
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
//include database connector class
require_once("{$include}/db_connector_mysql.inc.php");
//include api handler classes
require_once('test.inc.php');
require_once('accounts.inc.php');
//instantiate our restler object; call with argument "true" to run in production mode
$r = new Restler();
//bind api classes
$r->addAPIClass('Tests');
$r->addAPIClass('Accounts');
//set supported formats: JSON ONLY!
$r->setSupportedFormats('JsonFormat');
//handle the request
$r->handle();
测试.inc.php
<?php
class Tests {
private $dbc;
private $function_log_tag;
public function __construct () {
$this->dbc = DB_Connector_MySQL::getConnection();
$this->response = new stdClass();
}
/*
** @url GET /some/new/route
*/
public function get () {
//load required global variables
global $settings;
//set logging tag
$this->function_log_tag = '[' . __CLASS__ . '::' . __FUNCTION__ . '][v' . $settings['version'] . ']';
return $this->function_log_tag;
}
}
我一直在尝试许多不同的方法来试图找到根本问题。值得注意的是,我似乎无法找到“routes.php”文件,所以我可能认为这可能是服务器上的写权限问题。无论如何,任何帮助将不胜感激!