Skip to content

Commit 677835a

Browse files
committed
minor #16752 Use JsonResponse/BinaryFileResponse instead of Response (l-vo)
This PR was merged into the 4.4 branch. Discussion ---------- Use JsonResponse/BinaryFileResponse instead of Response Use JsonResponse/BinaryFileResponse as return type when json/file methods are used Commits ------- 18d9b73 Use JsonResponse/BinaryFileResponse instead of Response
2 parents ae8f5a5 + 18d9b73 commit 677835a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

controller.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ Returning JSON Response
601601
To return JSON from a controller, use the ``json()`` helper method. This returns a
602602
``JsonResponse`` object that encodes the data automatically::
603603

604-
use Symfony\Component\HttpFoundation\Response;
604+
use Symfony\Component\HttpFoundation\JsonResponse;
605605
// ...
606606

607-
public function index(): Response
607+
public function index(): JsonResponse
608608
{
609609
// returns '{"username":"jane.doe"}' and sets the proper Content-Type header
610610
return $this->json(['username' => 'jane.doe']);
@@ -623,10 +623,10 @@ Streaming File Responses
623623
You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController::file`
624624
helper to serve a file from inside a controller::
625625

626-
use Symfony\Component\HttpFoundation\Response;
626+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
627627
// ...
628628

629-
public function download(): Response
629+
public function download(): BinaryFileResponse
630630
{
631631
// send the file contents and force the browser to download it
632632
return $this->file('/path/to/some_file.pdf');
@@ -638,7 +638,7 @@ The ``file()`` helper provides some arguments to configure its behavior::
638638
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
639639
// ...
640640

641-
public function download(): Response
641+
public function download(): BinaryFileResponse
642642
{
643643
// load the file from the filesystem
644644
$file = new File('/path/to/some_file.pdf');

0 commit comments

Comments
 (0)