php - API Explorer 不使用 URL 参数

标签 php restler

我创建了一个 RESTful API,其中有一个作为 URL 变量传入的可选参数。当直接从浏览器执行时,它似乎可以正常工作,但是当在 API Explorer 中尝试它时,它会列出参数,但在执行时会忽略它。我不知道从哪里开始解决这个问题。任何帮助将不胜感激。

类定义如下:

class actions {

  /**
   * LIST available Actions
   *
   * List all the actions that a user (or app) can choose from. The response list  
   * will include [name],[slug/id], and [description] attributes. If you want a more complete set of 
   * meta attributes for the actions then you can specify "meta=all" in the request url. For full spec of
   * response please review LG_actions_list.json.
   *
   * @url GET /available
   *
   * @param $meta {@from url} Optional parameter to control the amount of meta-data passed back. Values are "none","normal", and "all"
   **/
  public function available ($meta="normal")
  {
    return "list actions (meta level set to $meta)";
  }

}

在这种情况下,我可以在 API 资源管理器中输入“all”作为 $meta 的值,但响应仍然是“列出操作(元级别设置为正常)”。

更新:

为了阐明此行为,我添加了 API Explorer 输出以及直接调用服务时获得的输出:

enter image description here

相比之下,实际使用 API 时我得到了正确的结果。在 Chrome 中输入:

http://[domain]/api/actions/available?meta=foobar

我得到了所需的输出:

"list actions (meta level set to foobar)"

最佳答案

您使用上述代码所做的事情几乎没有问题

  • 可选参数最好留给查询字符串
  • 当您使用 @url 添加手动路由时,不会为该方法添加自动路由

执行以下操作使其正常工作。

  • 将方法名称更改为 get 以将其映射到类的根
  • 关闭智能自动路由

现在在资源管理器中将列出两个操作

  • actions.json
  • actions.json/{meta}

.

class actions {

     /**
     * LIST available Actions
     *
     * List all the actions that a user (or app) can choose from. The response list
     * will include [name],[slug/id], and [description] attributes. If you want a more complete set of
     * meta attributes for the actions then you can specify "meta=all" in the request url. For full spec of
     * response please review LG_actions_list.json.
     *
     * @smart-auto-routing false
     * @param $meta Optional parameter to control the amount of meta-data passed back. Values are "none","normal", and "all"
     **/
    public function get ($meta="normal")
    {
        return "list actions (meta level set to $meta)";
    }

}

关于php - API Explorer 不使用 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12844909/

相关文章:

node.js - 如何使用 ReSTLer 下载网站并将其写入文件?

php - 在 reSTLer 中使用驼峰式大小写作为函数名

php - ReSTLer 3 - 参数的默认值阻止传递参数的能力

javascript - node.js reSTLer 调用的多个响应

php - 引导模式在 fullCalendar 插件中不起作用

php - Laravel 在非 Eloquent 模型上使用 ->lists()

php - 通过 CSV 复制记录更新数据库

php - 如何在 laravel 集体形式中设置默认值

php - ReSTLer API框架安装

php - 如何在 php 中使用 <select> 元素来导航数据库?