使用Restler为许多可选参数提供服务

时间:2014-01-20 18:42:09

标签: php web-services optional-parameters phpdoc restler

我使用许多可选参数进行服务:

/**
 * Change user settings
 *
 * @smart-auto-routing false
 * @url POST settings/
 * @param string $name New name of the user {@min 2}{@max 64}
 * @param string $surname New surname of the user {@min 2}{@max 64}
 * @param bool $sex 0 for man, 1 for girl
 * @param string $email New email address of the user {@type email}
 * @param bool $emailing 1 if user want to receive email from ilerter, 0 else
 * @param string $phone_number New phone number of the user {@min 4}
 * @param int $height {@from body}
 * @param int $weight {@from body}
 * @param int $eyes_color {@from body}
 * @param int $hair_color {@from body}
 * @param string $avatar {@from body}
 * @param string $description {@from body}
 * @return bool
 * @throws \Luracast\Restler\RestException
 */
public function settings($name, $surname, $sex, $email, $emailing, $phone_number,
$height = "", $weight = "", $eyes_color = "", $hair_color = "", $avatar = "",
$description = ""){

问题是当我决定只在可选参数中发送'avatar'时,我的服务将其带入$ height并返回

Bad Request: invalid value specified for `height`. Expecting integer value

当Restler不是第一个可选参数时,是否有办法捕获唯一良好的可选值?

1 个答案:

答案 0 :(得分:1)

当有太多路由相互重叠时,很难分辨哪个值映射到哪个参数

Restler 3尝试按类型匹配参数,因为height,weight,eyes_color,hair_color被输入为整数,所以当给出字符串值时它们不应该干扰,所以avatar可以将它作为第一行接收

但是因为你通过将字符串参数分配给高度,重量等来搞乱这种类型。它们现在被Restler视为字符串,因此最终会遇到上述问题

尝试将零指定为int值的默认值。