参数存在时Symfony2 MissingMandatoryParametersException

时间:2015-02-19 16:31:32

标签: symfony

让我感到困惑。我间歇性地收到了这个错误。

[2015-02-16 10:29:51] request.INFO: Matched route "app_site_default_edittargetsubmit" (parameters: "_controller": "App\SiteBundle\Controller\DefaultController::editTargetSubmitAction", "id": "17", "_route": "app_site_default_edittargetsubmit") [] []
[2015-02-16 10:29:51] security.DEBUG: Read SecurityContext from the session [] []
[2015-02-16 10:29:51] security.DEBUG: Reloading user from user provider. [] []
[2015-02-16 10:29:51] security.DEBUG: Username "user@example.com" was reloaded from user provider. [] []
[2015-02-16 10:29:51] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Routing\Exception\MissingMandatoryParametersException: "Some mandatory parameters are missing ("id") to generate a URL for route "adminCustomerTargets"." at /var/www/mysite/site/app/cache/prod/classes.php line 1264 {"exception":"[object] (Symfony\\Component\\Routing\\Exception\\MissingMandatoryParametersException: Some mandatory parameters are missing (\"id\") to generate a URL for route \"adminCustomerTargets\". at /var/www/ourbrightlink/site/app/cache/prod/classes.php:1264)"} []
[2015-02-16 10:29:51] security.DEBUG: Write SecurityContext in the session [] []

正如您在异常第一行的参数列表中所看到的,id参数在那里。 (参数:" _controller":" App \ SiteBundle \ Controller \ DefaultController :: editTargetSubmitAction"," id":" 17" ," _route":" app_site_default_edittargetsubmit")。

路线是通过注释定义的:

  /**
   * Handles the submission of the Edit form.
   *
   * @route( "target/edit/{id}" )
   * @method( {"POST"} )
   * @template( "AppSiteBundle:Default:editTarget.html.twig" )
   * @param Request $request
   * @param  $id
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   */
  public function editTargetSubmitAction( Request $request, $id )
  { ... }

这是Symfony 2.5.6。

连连呢? TIA

1 个答案:

答案 0 :(得分:0)

上面提到的帖子确实是答案。 将URL与路由匹配时,但从路由生成URL时,不会发生此错误。当在generateUrl()调用中没有第二个参数时会发生这种情况。