【问题标题】:Smart routing with PHPDoc not working with Restler v3使用 PHPDoc 的智能路由不适用于 Restler v3
【发布时间】:2013-02-27 10:31:52
【问题描述】:

我在 Restler PHP REST Framework v3 中实现智能 url 路由时遇到了一点问题。基本上看起来好像 Restler 忽略了我的 cmets。我在这里附上了我的 index.php 和 tests.inc.php 文件。正在发生的事情,即使是 PHPDoc cmets,似乎restler 正在忽略它们并且只响应默认的“测试”调用而不是“some/new/route”,正如我所期望的那样,基于提供的路由示例框架。

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”文件,所以我可能认为这可能是服务器上的写权限问题。无论如何,任何帮助将不胜感激!

【问题讨论】:

    标签: php api rest routes restler


    【解决方案1】:

    你的评论不是一个有效的 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;
        }
    }
    

    文档注释以/** 开头,而不是/*

    【讨论】:

    • 叹息...非常感谢。不敢相信我没听懂,哈哈。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多