如何解决此错误:
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']);
如果我未在请求中发送产品(字符串)选项,则会发生错误。有什么想法吗?