简体   繁体   中英

Symfony fosrestbundle optional parameter in route

I have an api rest and i try to give an optional paramter in my route like this :

/**
 * @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){

But i have an error :

[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?

Your are not importing that annotation class. Put something like this after the namespace declaration:

use FOS\RestBundle\Controller\Annotations as Rest;

so you can use it like what you have:

@Rest\View()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM