@@ -12,8 +12,11 @@ a server responding to the client that called it.
1212Working with the Response
1313=========================
1414
15- A Response class is instantiated for you and passed into your controllers. It can be accessed through
16- ``$this->response ``. Many times you will not need to touch the class directly, since CodeIgniter takes care of
15+ A Response class is instantiated for you and passed into your controllers. It can
16+ be accessed through ``$this->response ``. It is the same instance that
17+ ``Services::response() `` returns. We call it the global response instance.
18+
19+ Many times you will not need to touch the class directly, since CodeIgniter takes care of
1720sending the headers and the body for you. This is great if the page successfully created the content it was asked to.
1821When things go wrong, or you need to send very specific status codes back, or even take advantage of the
1922powerful HTTP caching, it's there for you.
@@ -40,20 +43,36 @@ You can set format an array into either JSON or XML and set the content type hea
4043Setting Headers
4144---------------
4245
46+ setHeader()
47+ ^^^^^^^^^^^
48+
4349Often, you will need to set headers to be set for the response. The Response class makes this very simple to do,
44- with the ``setHeader() `` method. The first parameter is the name of the header. The second parameter is the value,
50+ with the ``setHeader() `` method.
51+
52+ The first parameter is the name of the header. The second parameter is the value,
4553which can be either a string or an array of values that will be combined correctly when sent to the client.
54+
55+ .. literalinclude :: response/004.php
56+
4657Using these functions instead of using the native PHP functions allows you to ensure that no headers are sent
4758prematurely, causing errors, and makes testing possible.
4859
49- .. literalinclude :: response/004.php
60+ .. note :: This method just sets headers to the response instance. So, if you create
61+ and return another response instance (e.g., if you call :php:func: `redirect() `),
62+ the headers set here will not be sent automatically.
63+
64+ appendHeader()
65+ ^^^^^^^^^^^^^^
5066
5167If the header exists and can have more than one value, you may use the ``appendHeader() `` and ``prependHeader() ``
5268methods to add the value to the end or beginning of the values list, respectively. The first parameter is the name
5369of the header, while the second is the value to append or prepend.
5470
5571.. literalinclude :: response/005.php
5672
73+ removeHeader()
74+ ^^^^^^^^^^^^^^
75+
5776Headers can be removed from the response with the ``removeHeader() `` method, which takes the header name as the only
5877parameter. This is not case-sensitive.
5978
@@ -384,7 +403,9 @@ The methods provided by the parent class that are available are:
384403 .. note :: Prior to v4.2.7, the default values of ``$secure`` and ``$httponly`` were ``false``
385404 due to a bug, and these values from **app/Config/Cookie.php ** were never used.
386405
387- Sets a cookie containing the values you specify. There are two ways to
406+ Sets a cookie containing the values you specify to the Response instance.
407+
408+ There are two ways to
388409 pass information to this method so that a cookie can be set: Array
389410 Method, and Discrete Parameters:
390411
@@ -439,6 +460,8 @@ The methods provided by the parent class that are available are:
439460
440461 Delete an existing cookie.
441462
463+ .. note :: This also just sets browser cookie for deleting the cookie.
464+
442465 Only the ``name `` is required.
443466
444467 The ``prefix `` is only needed if you need to avoid name collisions with
0 commit comments