@@ -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
@@ -809,46 +815,39 @@ the :phpfunction:`json_encode` function is used.
809
815
File helper
810
816
~~~~~~~~~~~
811
817
812
- If you want to serve file use the
813
- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::file `
814
- helper::
815
-
816
- $this->file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT);
818
+ .. versionadded :: 3.2
819
+ The ``file() `` helper was introduced in Symfony 3.2.
817
820
818
- You can pass:
821
+ You can use :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::file `
822
+ to serve a file from inside a controller::
819
823
820
- * An instance of
821
- :class: `Symfony\\ Component\\ HttpFoundation\\ File `
822
- in ``$file `` parameter (you can customize ``$fileName `` and ``$disposition ``)
824
+ $this->file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT);
823
825
824
- * Path to file in ``$file `` parameter
826
+ You can pass an :phpclass: `SplFileInfo ` instance (like
827
+ :class: `Symfony\\ Component\\ HttpFoundation\\ File `) or the path to a file as
828
+ first argument. Using the second and third arguments, you can customize the
829
+ send filename and the disposition.
825
830
826
- Example usage::
831
+ .. code-block :: php
827
832
828
833
use Symfony\Component\HttpFoundation\File\File;
829
834
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
830
835
831
- // This will send file with original name as attachment to browser
832
836
public function fileAction()
833
837
{
834
- // Load file from file system
838
+ // load file from the file system
835
839
$file = new File('some_file.pdf');
836
840
837
- return $this->file($file);
841
+ // send the file as attachment to browser
842
+ return $this->file($file, 'custom_name.pdf');
838
843
}
839
844
840
- // Server file from specified path
841
845
public function pathFileAction()
842
846
{
847
+ // serve file from specified path
843
848
return $this->file('/path/to/my/picture.jpg');
844
849
}
845
850
846
- .. seealso ::
847
-
848
- Now that you know the basics you can continue your research on Symfony
849
- ``Request `` and ``Response `` object in the
850
- :ref: `HttpFoundation component documentation <component-http-foundation-request >`.
851
-
852
851
Creating Static Pages
853
852
---------------------
854
853
0 commit comments