你好,
我定义了一个 ParamConverter(用于 DoctrineParamConverter),例如
@ParamConverter("myparam", class="MyBundle:MyEntity", isOptional="true", options={"id" = "param_id"})
但是“可选”标志在 ParamConverterListener 中被覆盖
$configurations[$name]->setIsOptional($param->isOptional());
在街区之外
if (!isset($configurations[$name])) {
...
}
因此无法使用 DoctrineParamConverter 定义可选参数。
感谢您的反馈意见。
最好的祝福,
克里斯托夫
有可能,如果方法中的参数使用User $user = null
之类的值定义,则它是可选的。
@henrikbjorn
如果您对控制器上的一种方法使用多路由“使用 $user = null”不起作用
例如测试这段代码
/**
* @Route("/customer/{id}/message/{type}/create", name="fisan_frontend_message_create")
* @ParamConverter("Customer", class="\qwe\Entity\Customer", options={"id" = "id"}, isOptional="true")
*
* @Route("/creditor/{id}/message/{type}/create", name="fisan_frontend_message_create_creditor")
* @ParamConverter("Creditor", class="\qwe\Entity\Creditor", options={"id" = "id"}, isOptional="true")
*
* @Method({"POST"})
*
* <strong i="8">@param</strong> Request $request
* <strong i="9">@param</strong> Customer $customer
* <strong i="10">@param</strong> Creditor $creditor
* <strong i="11">@param</strong> string $type
*
* <strong i="12">@return</strong> JsonResponse
*/
public function createAction(Request $request, \Fisan\Entity\Customer $customer = null, \Fisan\Entity\Creditor $creditor = null, $id, $type = MessageTypeChoiceList::EMAIL)
{
}
对于第二条路线,由于第一个 ParamConverter 的结果工作 paramconverter,您会收到错误 404
ParamConverters 不在您定义的路线的上下文中使用。 它们是独立执行的
最有用的评论
有可能,如果方法中的参数使用
User $user = null
之类的值定义,则它是可选的。