在给定symfony选项解析器的情况下,参数resolve()必须是数组null

时间:2017-10-22 15:35:33

标签: symfony options-resolver

如何解决此错误:

Argument 1 passed to Symfony\Component\OptionsResolver\OptionsResolver::resolve() must be of the type array, null given

代码:

private function getProductOptions(Request $request)
{
    $resolver = new OptionsResolver();
    $resolver->setDefaults([
        'product' => null,
    ]);

    $resolver->setAllowedValues('product', null);
    return $resolver->resolve(json_decode($request->getContent()));
}
//...
$option = $this->getOption($request);
$user->setProduct($option['product']);

如果我未在请求中发送产品(字符串)选项,则会发生错误。有什么想法吗?

0 个答案:

没有答案