【问题标题】:Service with many optional parameters with Restler使用 Restler 提供许多可选参数的服务
【发布时间】:2014-01-20 18:42:08
【问题描述】:

我有使用许多可选参数的服务:

/**
 * 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 = ""){

问题是当我决定在可选参数中只发送“头像”时,我的服务将其放入 $height 并返回

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

当它不是第一个可选参数时,Restler 有没有办法捕捉唯一好的可选值?

【问题讨论】:

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


    【解决方案1】:

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

    Restler 3 尝试按类型匹配参数,因为 height、weight、eyes_color、hair_color 被键入为整数,因此当给定字符串值时它们不应干扰,因此 avatar 可以将其作为第一个来选择

    但是由于您通过将字符串参数分配给身高、体重等而弄乱了类型。它们现在被 Restler 视为字符串,因此最终出现上述问题

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

    【讨论】:

    • 非常感谢!现在运行良好
    猜你喜欢
    • 2010-12-15
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 2016-03-12
    • 1970-01-01
    • 2011-04-28
    • 2015-10-15
    相关资源
    最近更新 更多