Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 捕获JSON请求中的所有输入(使用Restler)_Php_Restler - Fatal编程技术网

Php 捕获JSON请求中的所有输入(使用Restler)

Php 捕获JSON请求中的所有输入(使用Restler),php,restler,Php,Restler,我有一个请求,其中大多数输入参数都作为JSON请求对象输入。出于文档的目的,我想指定用户可以输入的最常见字段,但是JSON请求中的名称值有很多变化,我不想记录所有这些,因为这会很麻烦 以下是我现在拥有的屏幕截图: 例如,如果我想输入一个名为“people with”的JSON属性,并将其设置为“['joe'、'paul'、'jane'”,那么在JSON中这将很容易做到,但我如何在我的PHP/Restler代码中获取它。目前,此服务的签名是: /** * ADD an Activity *

我有一个请求,其中大多数输入参数都作为JSON请求对象输入。出于文档的目的,我想指定用户可以输入的最常见字段,但是JSON请求中的名称值有很多变化,我不想记录所有这些,因为这会很麻烦

以下是我现在拥有的屏幕截图:

例如,如果我想输入一个名为“people with”的JSON属性,并将其设置为“['joe'、'paul'、'jane'”,那么在JSON中这将很容易做到,但我如何在我的PHP/Restler代码中获取它。目前,此服务的签名是:

/**
 * ADD an Activity
 *
 * Add a new action to a user's stream
 *
 * @url POST /{user_id}
 *
 * @param integer   $user_id    The user_id for whom the actions apply; you can insert the text "self" and it will resolve to the current/default user
 * @param string    $start_time {@from body} The date/time that the activity was started (YYYY-MM-DD or YYYY-MM-DD HH:mm:SS)
 * @param string    $action     {@from body} The action "slug name" that uniquely identifies an action
 * @param string    $end_time   {@from body} The date/time that the activity concluded (YYYY-MM-DD or YYYY-MM-DD HH:mm:SS)
 * @param string    $app_id     {@from body} The application that captured this activity
 * @param string    $proxy_user_id  {@from body} The person who captured this activity for the individual
 * @param string    $location   {@from body} The location information associated with this activity
*/
public function add_action ($user_id, $start_time, $action, $end_time=null, $app_id=null, $proxy_user_id=null, $location=null)
{
    // implement
}

p、 顺便说一句,我已经临时将这个API服务更改为PUT,以避免几天前提出的POST问题,这也影响了我在这里使用POST时的工作。

好的,解决这个问题的关键在于
$request\u data
关联数组。为了实现这两个文档(关键字段)为了能够在POST/PUT服务中动态接收值,您只需执行以下操作:

/**
 * ADD an Activity
 *
 * Add a new action to a user's stream
 *
 * @url PUT /{user_id}
 *
 * @param integer   $user_id    The user_id for whom the actions apply; you can insert the text "self" and it will resolve to the current/default user
 * @param string    $start_time {@from body} The date/time that the activity was started (YYYY-MM-DD or YYYY-MM-DD HH:mm:SS)
 * @param string    $action_nm  {@from body} The action "slug name" that uniquely identifies an action
 * @param string    $end_time   {@from body} The date/time that the activity concluded (YYYY-MM-DD or YYYY-MM-DD HH:mm:SS)
 * @param string    $app_id     {@from body} The application that captured this activity
 * @param string    $proxy_user_id  {@from body} The person who captured this activity for the individual
 * @param string    $location   {@from body} The location information associated with this activity
*/
public function add_activity ($user_id, $start_time, $action_nm, $end_time=null, $app_id=null, $proxy_user_id=null, $location=null, $request_data=null)
请注意,$request\u数据没有
@param
,但是$request\u数据现在挂在函数签名的末尾。现在想象一下,我已经通过了请求的JSON中的以下
'test':'me'
。现在我可以在我的处理程序中获得它:

echo $request_data['test']; // prints "me"
这是可行的,文档看起来也应该如此(参见上面的屏幕截图)

最后一点,对于那些好奇的人,您可以通过$request\u数据数组访问所有JSON变量。这意味着:

echo ($request_data['user_id'] === $user_id); // TRUE

唯一不希望出现的结果是$request_数据出现在文档中。有人知道避免这种情况的方法吗?$request_数据不应该出现在那里,这是参考资料中的一个错误。php将被修复soonGreat!我今天将合并它。