jjzjj

fosrestbundle

全部标签

php - 使用 FOSRestBundle 将 POST 请求主体序列化为数组

我正在尝试使用Symfony3和FOSRestBundle创建一个Rest网络服务。我来自Spring+Jackson背景,所以我正在努力做到这一点,以便您可以将对象作为请求主体传递给Controller​​,请求主体成为函数参数并返回序列化为json的对象,到目前为止,我设法让它适用于所有内容除了数组。这是我的代码:配置:#FOSRestBundlefos_rest:param_fetcher_listener:truebody_listener:enabled:truedecoders:json:fos_rest.decoder.jsonformat_listener:rules:

php - Symfony2 FOSRESTBundle REST API 返回 PDF

我在里面制作了一个Bundle和一个RESTController。“index”方法返回JSON格式的数组,没问题:MyBundle/Controller/Api/Rest/BaconController.phpclassBaconControllerextendsControllerimplementsClassResourceInterface{/***@varRequest$request*@returnarray*@Rest\View*/publicfunctioncgetAction(Request$request){$mediaType=$request->attribut

php - 使用 Symfony/FosRestBundle/JMS Serializer 实现字段白名单的建议

我目前正在学习如何使用Symfony3(带有FOSRestBundle)和JMSSerializer来实现一个相对简单的API。我最近一直在尝试实现指定作为消费客户端的能力,哪些字段应该在响应中返回(请求的实体和关系中的字段)。例如;不包含查询字符串的/posts将返回所有Post实体属性(例如标题、正文、posted_at等),但没有关系。/posts?fields[]=id&fields[]=title将只返回帖子的ID和标题(但同样,没有关系)/posts?include[]=comment将包含上述内容,但具有Comment关系(及其所有属性)/posts?include[]=

php - FosUserBundle 与 FosRestBundle 集成

有没有人有示例或知道如何将FOSRestBundle与FOSUserBundle一起实现。我已经使用Symfony2和FOSUserBundle开发了一个Web应用程序,但我想为api层添加FOSRestBundle。我希望能够将用户名和密码传递给它,并从代表登录用户的FOSUserBundle接收某种类型的token,然后我可以在其他api调用之间来回传递。有谁知道这样做的好方法? 最佳答案 FOSUserBundle应该是原生的“restful”意味着它可以遵循REST的建议。但是,它并非设计为与FOSRestBundle一起原

php - Symfony2 注释继承

在我的项目中,我有一个BaseController类,它实现了我所有Controller使用的几种方法。现在我想为该基类添加@QueryParam。我的类(class)看起来像这样:classDoctrineRESTQueryControllerextendsFOSRestController{/***@QueryParam(name="start",default=0)*@QueryParam(name="limit",default=null)*/publicfunctiongetQueryResponseAction(ParamFetcher$paramFetcher){}}现在

php - 如何使用 FOSRest 和 Symfony 3.0 正确执行 REST API POST 调用

对于我目前正在构建的API,我希望能够发送包含以下内容的JSON主体的请求{"title":"foo"}为名为Project的实体创建新的数据库记录。我制作了一个Controller,它是FOSRestController的子类。为了创建一个项目,我做了一个Action/***@Route("/")**@ApiDoc(*section="Project",*resource=true,*input={"class"="AppBundle\Form\API\ProjectType"},*description="Createsanewproject",*statusCodes={*201

php - FOSRestBundle 在获取 URL 中添加 'S'

//MySomethingController.php//looknospublicfunctiongetSomethingAction($args){...}//路由.ymlmy_something:type:restresource:Blah\Bundle\BlahBundle\Controller\MySomethingController运行:phpapp/consolerouter:debug输出:[router]CurrentroutesNameMethodPatternget_somethingGET/somethings/{args}.{_format}为什么路由是“s

php - 具有 RESTful 身份验证的 Symfony2 应用程序,使用 FOSRestBundle 和 FOSUserBundle

我正在为我的JS驱动应用制作RESTAPI。在登录期间,登录表单通过AJAX提交到我的API的url/rest/login。如果登录成功,返回204如果失败,返回401虽然我为API和应用程序本身分离了防火墙,但它们共享相同的上下文,这应该意味着,当用户针对API进行身份验证时,他也针对应用程序进行了身份验证。因此,当服务器返回204时,页面将重新加载并且它应该将用户重定向到应用程序,因为他现在已经登录。我尝试使用FOSUserBundle的预制check_login页面并指向那里的/rest/login。login:path:/rest/logindefaults:_controll

php - FOSRestBundle 在 Symfony 4.1 中不起作用

我在使用在Symfony4.1项目下工作的FOSRestBundle返回View时遇到问题。这是来self的Controller的代码:classNewsControllerextendsFOSRestController{publicfunctiongetNewsAction(){$data=['news1','news2'];$view=$this->view($data,200);return$this->handleView($view);}}fos_rest.yamlfos_rest:param_fetcher_listener:trueallowed_methods_lis

php - FOSRestBundle 设置返回 JSON 但仍然要求 Twig 模板

我已将FOSRestBundle配置如下:#FOSRestBundlefos_rest:param_fetcher_listener:truebody_listener:trueformat_listener:rules:-{path:^/,priorities:[json,html],fallback_format:~,prefer_extension:true}media_type:version_regex:'/(v|version)=(?P[0-9\.]+)/'body_converter:enabled:truevalidate:trueview:mime_types:jso