@@ -782,6 +782,12 @@ There are also special classes to make certain kinds of responses easier:
782
782
:class: `Symfony\\ Component\\ HttpFoundation\\ StreamedResponse `.
783
783
See :ref: `streaming-response `.
784
784
785
+ .. seealso ::
786
+
787
+ Now that you know the basics you can continue your research on Symfony
788
+ ``Request `` and ``Response `` object in the
789
+ :ref: `HttpFoundation component documentation <component-http-foundation-request >`.
790
+
785
791
JSON Helper
786
792
~~~~~~~~~~~
787
793
@@ -806,11 +812,38 @@ If the :doc:`serializer service </cookbook/serializer>` is enabled in your
806
812
application, contents passed to ``json() `` are encoded with it. Otherwise,
807
813
the :phpfunction: `json_encode ` function is used.
808
814
809
- .. seealso ::
815
+ File helper
816
+ ~~~~~~~~~~~
810
817
811
- Now that you know the basics you can continue your research on Symfony
812
- ``Request `` and ``Response `` object in the
813
- :ref: `HttpFoundation component documentation <component-http-foundation-request >`.
818
+ .. versionadded :: 3.2
819
+ The ``file() `` helper was introduced in Symfony 3.2.
820
+
821
+ You can use the :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::file `
822
+ helper to serve a file from inside a controller::
823
+
824
+ public function fileAction()
825
+ {
826
+ // send the file contents and force the browser to download it
827
+ return $this->file('/path/to/some_file.pdf');
828
+ }
829
+
830
+ The ``file() `` helper provides some arguments to configure its behavior::
831
+
832
+ use Symfony\Component\HttpFoundation\File\File;
833
+ use Symfony\Component\HttpFoundation\ResponseHeaderBag;
834
+
835
+ public function fileAction()
836
+ {
837
+ // load the file from the filesystem
838
+ $file = new File('/path/to/some_file.pdf');
839
+ return $this->file($file);
840
+
841
+ // rename the downloaded file
842
+ return $this->file($file, 'custom_name.pdf');
843
+
844
+ // display the file contents in the browser instead of downloading it
845
+ $this->file('invoice_3241.pdf', 'my_invoice.pdf', ResponseHeaderBag::DISPOSITION_INLINE);
846
+ }
814
847
815
848
Creating Static Pages
816
849
---------------------
0 commit comments