在Restler、PHP框架v3中实现智能url路由有点问题。从根本上看,莱斯特勒似乎忽视了我的评论。我已经在这里附上了我的index.php和tests.inc.php文件。现在发生的事情,即使是PHPDoc注释,似乎也忽略了它们,并且只响应默认的“测试”调用,而不是“一些/新/路由”,正如我根据框架提供的路由示例所期望的那样。
index.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();test.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“文件,因此我可能认为这可能是服务器上的写权限问题。无论如何,任何帮助都将不胜感激!
发布于 2013-03-12 12:51:23
您的评论不是有效的PHPDoc评论,它只是一个常规的评论。
有关正确的语法,请参阅以下内容
<?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;
}
}Doc注释以/**而不是/*开头
https://stackoverflow.com/questions/15352295
复制相似问题