脚本宝典收集整理的这篇文章主要介绍了php – symfony / FOSRestBundle:空的JSON响应(使用symfony体现的序列化程序),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
public function getPlacesAction(Request $request) { $places = $this->get('doctrine.orm.entITy_manager') ->getRepository('AppBundle:Place') ->findAll(); /* @VAR $places Place[] */ $formatted = []; foreach ($places as $place) { $formatted[] = [ 'id' => $place->getId(),'name' => $place->getName(),'address' => $place->getAddress(),]; } return new JsonResponse($formatted); }
但后来我尝试直接序列化$places,使用fost Rest的视图处理程序(在config.yML中)
fos_rest: routing_loader: include_format: false view: view_response_listener: true format_listener: rules: - { path: '^/',PRiorities: ['json'],fallback_format: 'json' }
并将我的控制器中的功能更改为以下代码,我得到了我的JSON响应,但“{[],[],[]}”之间没有任何内容(我的数据库中有3个条目):
public function getPlacesAction(Request $request) { $places = $this->get('doctrine.orm.entity_manager') ->getRepository('AppBundle:Place') ->findAll(); /* @var $places Place[] */ return $places; }
这是我关于stackoverflow的第一篇文章,所以我希望我的问题很清楚,祝你有愉快的一天.
以上是脚本宝典为你收集整理的php – symfony / FOSRestBundle:空的JSON响应(使用symfony体现的序列化程序)全部内容,希望文章能够帮你解决php – symfony / FOSRestBundle:空的JSON响应(使用symfony体现的序列化程序)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。