最新消息:文章中包含代码时,请遵守代码高亮规范!

Symfony返回json格式数据的官方用法

PHP Surfin 4613浏览 0评论

之前在看Symfony的说明书时,关于The Request Object这块,
看到Controller这个单元(http://symfony.com/doc/current/book/controller.html)

use Symfony\Component\HttpFoundation\Response;

// create a simple Response with a 200 status code (the default)
$response = new Response('Hello '.$name, Response::HTTP_OK);

// create a JSON-response with a 200 status code
$response = new Response(json_encode(array('name' => $name)));
$response->headers->set('Content-Type', 'application/json');

转载时请注明出处及相应链接,本文永久地址:https://blog.yayuanzi.com/9415.html

您必须 登录 才能发表评论!