Api Symfony fosrestbundle路由中的可选参数
我有一个api rest,我尝试在我的路由中提供一个可选参数,如下所示:Api Symfony fosrestbundle路由中的可选参数,api,symfony,fosrestbundle,Api,Symfony,Fosrestbundle,我有一个api rest,我尝试在我的路由中提供一个可选参数,如下所示: /** * @Rest\View * @Rest\Get("/dossier/{idDossier}", requirements={"idDossier" = "\d+"}, defaults={"idDossier" = null}) * @ApiDoc( * description="...", * parameters={ * {"name"="idDossier", "dataType"
/**
* @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?
您没有导入该注释类。在名称空间声明之后放置如下内容:
use FOS\RestBundle\Controller\Annotations as Rest;
因此,您可以像使用现有设备一样使用它:
@Rest\View()
检查是否有此语句
使用FOS\RestBundle\Controller\Annotations作为Rest代码>谢谢你的工作,但我有一个新的错误,我已经回答了从nelmio发布的mdmathe apidoc?检查此语句使用Nelmio\ApiDocBundle\Annotation\ApiDoc代码>谢谢,没问题!在此之后,我对“APIDoc”也有相同的定义,所以我做了相同的操作:使用FOS\RestBundle\Controller\Annotations作为APIDoc;我可以调用两次注释作为apidoc和rest?现在,我有一个错误:getDossierAction()不存在。我的函数是:公共函数getDossierAction($idDossier,Request$Request){…那么为什么不存在呢?没关系,我不需要“apidoc”,所有这些都可以使用:/***@Rest\View*@Rest\Get(“/dossier/{idDossier}”,requirements={“idDossier”=“\d+”},默认值={“idDossier”=null})*/再次感谢:)