Symfony fosrestbundle 路由中的可选参数

Symfony fosrestbundle optional parameter in route

我有一个 api 休息,我尝试在我的路线中提供一个可选参数,如下所示:

/**
 * @Rest\View
 * @Rest\Get("/dossier/{idDossier}", requirements={"idDossier" = "\d+"}, defaults={"idDossier" = null})
 * @ApiDoc(
 *  description="...",
 *  parameters={
 *      {"name"="idDossier", "dataType"="integer", "required"=false, "description"="Folder Id"}
 *  }
 * )
 */

public function getDossierAction($idDossier = null, Request $request){

但是我有一个错误:

[Semantical Error] The annotation "@Rest\View" in method ...\Controller\DossierAPIController::getDossierAction() was never imported. Did you maybe forget to add a "use" statement for this annotation?

您没有导入该注释 class。在名称空间声明之后放置类似这样的内容:

use FOS\RestBundle\Controller\Annotations as Rest;

所以您可以像现有的一样使用它:

@Rest\View()