1

I want some parameters to be optional in the JSON body. I have made phpdocs and set the parameter to null:

/**
 * Create a new text
 *
 * @param int $product_id       product id
 * @param int $template_id      {@from body} template id
 * @param string $language      {@from body} the language of the text
 * @param string $name          {@from body} product name
 *
 * @url POST {product_id}/texts
 */
public function postText($product_id, $template_id, $market_id = null)
{ }

But Restler gives me:

{
   "error": {
   "code": 400,
   "message": "Bad Request: market_id is missing."
   }
}

How do I specify a parameter to be optional?

4

1 回答 1

2

知道了。我的代码不完整,实际上我有多个参数,例如:

function($a, $b = null, $c, $d = 5)

问题是这$b是必需的,尽管我已经为它设置了一个值。通过将所有可选参数放在最后来解决问题,如下所示:

function($a, $c, $b = null, $d = 5)
于 2012-10-24T05:11:34.727 回答