我创建了一个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 Explorers输出和我直接调用服务时得到的输出:
相比之下,当实际使用API时,我得到了正确的结果。将其输入Chrome:
我得到了所需的输出:
“列出操作(设置为foobar的元级别)”
答案 0 :(得分:2)
使用上述代码
时,您所做的事情几乎没有问题@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)";
}
}