From 71a1558cb774a35c6e62315a602e7e4e00938cc6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 08:51:10 +0900 Subject: [PATCH 01/18] docs: add sub section titles --- user_guide_src/source/incoming/incomingrequest.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index d3b04bd0c698..95c2b570dc6a 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -99,6 +99,9 @@ With CodeIgniter's built-in methods you can simply do this: Getting Data ============ +getVar() +-------- + The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data from ``$_GET``, ``$POST``, or ``$_COOKIE`` (depending on php.ini `request-order `_). .. warning:: If you want to validate POST data only, don't use ``getVar()``. @@ -109,6 +112,9 @@ The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data fr .. note:: If the incoming request has a ``Content-Type`` header set to ``application/json``, the ``getVar()`` method returns the JSON data instead of ``$_REQUEST`` data. +get*() +------ + While this is convenient, you will often need to use a more specific method, like: From 4647fe3046ed4b469d4571ed6381265fe50546f8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 08:59:09 +0900 Subject: [PATCH 02/18] docs: add missing $_COOKIE --- user_guide_src/source/incoming/incomingrequest.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 95c2b570dc6a..26ee9857ed76 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -76,7 +76,8 @@ You can also check if the request was made through and HTTPS connection with the Retrieving Input **************** -You can retrieve input from ``$_SERVER``, ``$_GET``, ``$_POST``, and ``$_ENV`` through the Request object. +You can retrieve input from ``$_GET``, ``$_POST``, ``$_COOKIE``, ``$_SERVER`` +and ``$_ENV`` through the Request object. The data is not automatically filtered and returns the raw input data as passed in the request. .. note:: It is bad practice to use global variables. Basically, it should be avoided From 2032f7d50b53bc6c407d185e1c5488f7538c6c7e Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 08:59:25 +0900 Subject: [PATCH 03/18] docs: fix incorrect sample code getVar() is not guaranteed to get POST data. --- user_guide_src/source/incoming/incomingrequest/008.php | 2 +- user_guide_src/source/incoming/incomingrequest/014.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest/008.php b/user_guide_src/source/incoming/incomingrequest/008.php index c1ee739bf50c..1f75ce279958 100644 --- a/user_guide_src/source/incoming/incomingrequest/008.php +++ b/user_guide_src/source/incoming/incomingrequest/008.php @@ -1,3 +1,3 @@ getVar('foo'); +$something = $request->getPost('foo'); diff --git a/user_guide_src/source/incoming/incomingrequest/014.php b/user_guide_src/source/incoming/incomingrequest/014.php index 564fc543143b..8455402e59b9 100644 --- a/user_guide_src/source/incoming/incomingrequest/014.php +++ b/user_guide_src/source/incoming/incomingrequest/014.php @@ -1,3 +1,3 @@ getVar('email', FILTER_SANITIZE_EMAIL); +$email = $request->getPost('email', FILTER_SANITIZE_EMAIL); From 4e48de908d41241476aecde49936d85626067241 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:01:36 +0900 Subject: [PATCH 04/18] docs: move getVar() section down The method is not recommended. --- .../source/incoming/incomingrequest.rst | 58 ++++++++++++++----- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 26ee9857ed76..f111fa44c22d 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -100,37 +100,67 @@ With CodeIgniter's built-in methods you can simply do this: Getting Data ============ -getVar() +getGet() -------- -The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data from ``$_GET``, ``$POST``, or ``$_COOKIE`` (depending on php.ini `request-order `_). - -.. warning:: If you want to validate POST data only, don't use ``getVar()``. - Newer values override older values. POST values may be overridden by the - cookies if they have the same name, and you set "C" after "P" in - `request-order `_. +The ``getGet()`` method will pull from ``$_GET``. -.. note:: If the incoming request has a ``Content-Type`` header set to ``application/json``, - the ``getVar()`` method returns the JSON data instead of ``$_REQUEST`` data. +* ``$request->getGet()`` -get*() ------- +getPost() +--------- -While this -is convenient, you will often need to use a more specific method, like: +The ``getPost()`` method will pull from ``$_POST``. -* ``$request->getGet()`` * ``$request->getPost()`` + +getCookie() +----------- + +The ``getCookie()`` method will pull from ``$_COOKIE``. + * ``$request->getCookie()`` + +getServer() +----------- + +The ``getServer()`` method will pull from ``$_SERVER``. + * ``$request->getServer()`` + +getEnv() +-------- + +The ``getEnv()`` method will pull from ``$_ENV``. + * ``$request->getEnv()`` +getPostGet() +------------ + In addition, there are a few utility methods for retrieving information from either ``$_GET`` or ``$_POST``, while maintaining the ability to control the order you look for it: * ``$request->getPostGet()`` - checks ``$_POST`` first, then ``$_GET`` + +getGetPost() +------------ + * ``$request->getGetPost()`` - checks ``$_GET`` first, then ``$_POST`` +getVar() +-------- + +The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data from ``$_GET``, ``$POST``, or ``$_COOKIE`` (depending on php.ini `request-order `_). + +.. warning:: If you want to validate POST data only, don't use ``getVar()``. + Newer values override older values. POST values may be overridden by the + cookies if they have the same name, and you set "C" after "P" in + `request-order `_. + +.. note:: If the incoming request has a ``Content-Type`` header set to ``application/json``, + the ``getVar()`` method returns the JSON data instead of ``$_REQUEST`` data. + .. _incomingrequest-getting-json-data: Getting JSON Data From ed117dccbdeec230cfb01e85d4edb38cfff31f1f Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:06:12 +0900 Subject: [PATCH 05/18] docs: fix indent --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index f111fa44c22d..659861fd4595 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -417,7 +417,7 @@ The methods provided by the parent classes that are available are: :returns: ``$_POST`` if no parameters supplied, otherwise the POST value if found, or null if not :rtype: array|bool|float|int|object|string|null - This method is identical to ``getVar()``, only it fetches POST data. + This method is identical to ``getVar()``, only it fetches POST data. .. php:method:: getPostGet([$index = null[, $filter = null[, $flags = null]]]) From d46f10a2413aa979dd678ae32ac699a0325bc8e7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:07:39 +0900 Subject: [PATCH 06/18] docs: fix incorrect descriptions getVar() does not return POST items. --- user_guide_src/source/incoming/incomingrequest.rst | 6 +++--- user_guide_src/source/incoming/incomingrequest/029.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 659861fd4595..31894ce50e4c 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -378,15 +378,15 @@ The methods provided by the parent classes that are available are: .. literalinclude:: incomingrequest/028.php - To return an array of all POST items call without any parameters. + To return an array of all REQUEST items call without any parameters. - To return all POST items and pass them through the filter, set the + To return all REQUEST items and pass them through the filter, set the first parameter to null while setting the second parameter to the filter you want to use: .. literalinclude:: incomingrequest/029.php - To return an array of multiple POST parameters, pass all the required keys as an array: + To return an array of multiple REQUEST parameters, pass all the required keys as an array: .. literalinclude:: incomingrequest/030.php diff --git a/user_guide_src/source/incoming/incomingrequest/029.php b/user_guide_src/source/incoming/incomingrequest/029.php index 62390522b9b6..98da556e20a8 100644 --- a/user_guide_src/source/incoming/incomingrequest/029.php +++ b/user_guide_src/source/incoming/incomingrequest/029.php @@ -1,4 +1,4 @@ getVar(null, FILTER_SANITIZE_FULL_SPECIAL_CHARS); -// returns all POST items with string sanitation +// returns all REQUEST items with string sanitation From d0c1d5b6e5d08e4997492ab15a1e823fc1a50956 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:16:07 +0900 Subject: [PATCH 07/18] docs: add explanations to getGet() getVar() is not recommended. --- .../source/incoming/incomingrequest.rst | 29 ++++++++++++++++++- .../source/incoming/incomingrequest/041.php | 3 ++ .../source/incoming/incomingrequest/042.php | 3 ++ .../source/incoming/incomingrequest/043.php | 4 +++ .../source/incoming/incomingrequest/044.php | 3 ++ .../source/incoming/incomingrequest/045.php | 3 ++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 user_guide_src/source/incoming/incomingrequest/041.php create mode 100644 user_guide_src/source/incoming/incomingrequest/042.php create mode 100644 user_guide_src/source/incoming/incomingrequest/043.php create mode 100644 user_guide_src/source/incoming/incomingrequest/044.php create mode 100644 user_guide_src/source/incoming/incomingrequest/045.php diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 31894ce50e4c..714446ee66e6 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -405,7 +405,34 @@ The methods provided by the parent classes that are available are: :returns: ``$_GET`` if no parameters supplied, otherwise the GET value if found, or null if not :rtype: array|bool|float|int|object|string|null - This method is identical to ``getVar()``, only it fetches GET data. + The first parameter will contain the name of the GET item you are looking for: + + .. literalinclude:: incomingrequest/041.php + + The method returns null if the item you are attempting to retrieve + does not exist. + + The second optional parameter lets you run the data through the PHP's + filters. Pass in the desired filter type as the second parameter: + + .. literalinclude:: incomingrequest/042.php + + To return an array of all GET items call without any parameters. + + To return all REQUEST items and pass them through the filter, set the + first parameter to null while setting the second parameter to the filter + you want to use: + + .. literalinclude:: incomingrequest/043.php + + To return an array of multiple GET parameters, pass all the required keys as an array: + + .. literalinclude:: incomingrequest/044.php + + Same rule applied here, to retrieve the parameters with filtering, set the second parameter to + the filter type to apply: + + .. literalinclude:: incomingrequest/045.php .. php:method:: getPost([$index = null[, $filter = null[, $flags = null]]]) diff --git a/user_guide_src/source/incoming/incomingrequest/041.php b/user_guide_src/source/incoming/incomingrequest/041.php new file mode 100644 index 000000000000..b05ea2336c45 --- /dev/null +++ b/user_guide_src/source/incoming/incomingrequest/041.php @@ -0,0 +1,3 @@ +getGet('some_data'); diff --git a/user_guide_src/source/incoming/incomingrequest/042.php b/user_guide_src/source/incoming/incomingrequest/042.php new file mode 100644 index 000000000000..567b26454336 --- /dev/null +++ b/user_guide_src/source/incoming/incomingrequest/042.php @@ -0,0 +1,3 @@ +getGet('some_data', FILTER_SANITIZE_FULL_SPECIAL_CHARS); diff --git a/user_guide_src/source/incoming/incomingrequest/043.php b/user_guide_src/source/incoming/incomingrequest/043.php new file mode 100644 index 000000000000..4bd67d42046c --- /dev/null +++ b/user_guide_src/source/incoming/incomingrequest/043.php @@ -0,0 +1,4 @@ +getGet(null, FILTER_SANITIZE_FULL_SPECIAL_CHARS); +// returns all GET items with string sanitation diff --git a/user_guide_src/source/incoming/incomingrequest/044.php b/user_guide_src/source/incoming/incomingrequest/044.php new file mode 100644 index 000000000000..3e482e7a8ad4 --- /dev/null +++ b/user_guide_src/source/incoming/incomingrequest/044.php @@ -0,0 +1,3 @@ +getGet(['field1', 'field2']); diff --git a/user_guide_src/source/incoming/incomingrequest/045.php b/user_guide_src/source/incoming/incomingrequest/045.php new file mode 100644 index 000000000000..b0b0de81e1cd --- /dev/null +++ b/user_guide_src/source/incoming/incomingrequest/045.php @@ -0,0 +1,3 @@ +getGet(['field1', 'field2'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); From 66b8e26fed143536cd1039dbdcc6347b0eeedc5e Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:20:15 +0900 Subject: [PATCH 08/18] docs: remove detailed explanations in getVar() getVar() is not recommended. --- .../source/incoming/incomingrequest.rst | 31 ++----------------- .../source/incoming/incomingrequest/027.php | 3 -- .../source/incoming/incomingrequest/028.php | 3 -- .../source/incoming/incomingrequest/029.php | 4 --- .../source/incoming/incomingrequest/030.php | 3 -- .../source/incoming/incomingrequest/031.php | 3 -- 6 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 user_guide_src/source/incoming/incomingrequest/027.php delete mode 100644 user_guide_src/source/incoming/incomingrequest/028.php delete mode 100644 user_guide_src/source/incoming/incomingrequest/029.php delete mode 100644 user_guide_src/source/incoming/incomingrequest/030.php delete mode 100644 user_guide_src/source/incoming/incomingrequest/031.php diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 714446ee66e6..d7a268dfec24 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -366,34 +366,7 @@ The methods provided by the parent classes that are available are: :returns: ``$_REQUEST`` if no parameters supplied, otherwise the REQUEST value if found, or null if not :rtype: array|bool|float|int|object|string|null - The first parameter will contain the name of the REQUEST item you are looking for: - - .. literalinclude:: incomingrequest/027.php - - The method returns null if the item you are attempting to retrieve - does not exist. - - The second optional parameter lets you run the data through the PHP's - filters. Pass in the desired filter type as the second parameter: - - .. literalinclude:: incomingrequest/028.php - - To return an array of all REQUEST items call without any parameters. - - To return all REQUEST items and pass them through the filter, set the - first parameter to null while setting the second parameter to the filter - you want to use: - - .. literalinclude:: incomingrequest/029.php - - To return an array of multiple REQUEST parameters, pass all the required keys as an array: - - .. literalinclude:: incomingrequest/030.php - - Same rule applied here, to retrieve the parameters with filtering, set the second parameter to - the filter type to apply: - - .. literalinclude:: incomingrequest/031.php + This method is identical to ``getGet()``, only it fetches REQUEST data. .. php:method:: getGet([$index = null[, $filter = null[, $flags = null]]]) @@ -444,7 +417,7 @@ The methods provided by the parent classes that are available are: :returns: ``$_POST`` if no parameters supplied, otherwise the POST value if found, or null if not :rtype: array|bool|float|int|object|string|null - This method is identical to ``getVar()``, only it fetches POST data. + This method is identical to ``getGet()``, only it fetches POST data. .. php:method:: getPostGet([$index = null[, $filter = null[, $flags = null]]]) diff --git a/user_guide_src/source/incoming/incomingrequest/027.php b/user_guide_src/source/incoming/incomingrequest/027.php deleted file mode 100644 index aa4f01787b4b..000000000000 --- a/user_guide_src/source/incoming/incomingrequest/027.php +++ /dev/null @@ -1,3 +0,0 @@ -getVar('some_data'); diff --git a/user_guide_src/source/incoming/incomingrequest/028.php b/user_guide_src/source/incoming/incomingrequest/028.php deleted file mode 100644 index 3bc49822b301..000000000000 --- a/user_guide_src/source/incoming/incomingrequest/028.php +++ /dev/null @@ -1,3 +0,0 @@ -getVar('some_data', FILTER_SANITIZE_FULL_SPECIAL_CHARS); diff --git a/user_guide_src/source/incoming/incomingrequest/029.php b/user_guide_src/source/incoming/incomingrequest/029.php deleted file mode 100644 index 98da556e20a8..000000000000 --- a/user_guide_src/source/incoming/incomingrequest/029.php +++ /dev/null @@ -1,4 +0,0 @@ -getVar(null, FILTER_SANITIZE_FULL_SPECIAL_CHARS); -// returns all REQUEST items with string sanitation diff --git a/user_guide_src/source/incoming/incomingrequest/030.php b/user_guide_src/source/incoming/incomingrequest/030.php deleted file mode 100644 index 9e555a2f3143..000000000000 --- a/user_guide_src/source/incoming/incomingrequest/030.php +++ /dev/null @@ -1,3 +0,0 @@ -getVar(['field1', 'field2']); diff --git a/user_guide_src/source/incoming/incomingrequest/031.php b/user_guide_src/source/incoming/incomingrequest/031.php deleted file mode 100644 index 98c6f35e367d..000000000000 --- a/user_guide_src/source/incoming/incomingrequest/031.php +++ /dev/null @@ -1,3 +0,0 @@ -getVar(['field1', 'field2'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); From 79e517dbcfdf2e71ae32d43804ab2ad0b9d0ae3a Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:22:56 +0900 Subject: [PATCH 09/18] docs: fix replacement mistake --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index d7a268dfec24..91fd26fcb6aa 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -492,7 +492,7 @@ The methods provided by the parent classes that are available are: :rtype: array|bool|float|int|object|string|null This method is identical to the ``getPost()``, ``getGet()`` and ``getCookie()`` - methods, only it fetches getServer data (``$_SERVER``): + methods, only it fetches Server data (``$_SERVER``): .. literalinclude:: incomingrequest/036.php From 9f46435d4f9f3c9c88e4078a966a44d9d1fc40e3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:24:12 +0900 Subject: [PATCH 10/18] docs: fix outdated description --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 91fd26fcb6aa..45336f3397e4 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -508,7 +508,7 @@ The methods provided by the parent classes that are available are: :returns: The User Agent string, as found in the SERVER data, or null if not found. :rtype: CodeIgniter\\HTTP\\UserAgent - This method returns the User Agent string from the SERVER data: + This method returns the User Agent instance from the SERVER data: .. literalinclude:: incomingrequest/038.php From 76789fd495307a3fc7571b848c7b2ba0271a5655 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:26:31 +0900 Subject: [PATCH 11/18] docs: add () after function name --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 45336f3397e4..ffcd68e1e14a 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -177,7 +177,7 @@ By default, this will return any objects in the JSON data as objects. If you wan arrays, pass in ``true`` as the first parameter. The second and third parameters match up to the ``depth`` and ``options`` arguments of the -`json_decode `_ PHP function. +`json_decode() `_ PHP function. If the incoming request has a ``Content-Type`` header set to ``application/json``, you can also use ``getVar()`` to get the JSON stream. Using ``getVar()`` in this way will always return an object. From e6faa70e51ed3b6e7f1d43235d2d2d919110b48b Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:31:34 +0900 Subject: [PATCH 12/18] docs: remove description getVar() is not recommended. --- user_guide_src/source/incoming/incomingrequest.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index ffcd68e1e14a..fe7d46859ba7 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -179,9 +179,6 @@ arrays, pass in ``true`` as the first parameter. The second and third parameters match up to the ``depth`` and ``options`` arguments of the `json_decode() `_ PHP function. -If the incoming request has a ``Content-Type`` header set to ``application/json``, you can also use ``getVar()`` to get -the JSON stream. Using ``getVar()`` in this way will always return an object. - Getting Specific Data from JSON =============================== From 1e07684cfbd2d450a589d16808d591ec0b8738df Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:36:27 +0900 Subject: [PATCH 13/18] docs: fix param names --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index fe7d46859ba7..d1fad9b7724f 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -176,7 +176,7 @@ You can grab the contents of ``php://input`` as a JSON stream with ``getJSON()`` By default, this will return any objects in the JSON data as objects. If you want that converted to associative arrays, pass in ``true`` as the first parameter. -The second and third parameters match up to the ``depth`` and ``options`` arguments of the +The second and third parameters match up to the ``$depth`` and ``$flags`` arguments of the `json_decode() `_ PHP function. Getting Specific Data from JSON From 099a884e925be54351da62f8b88b03741fca41b3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:39:46 +0900 Subject: [PATCH 14/18] docs: replace getVar() with getJsonVar() getVar() is not recommended. --- user_guide_src/source/incoming/incomingrequest.rst | 7 +++---- user_guide_src/source/incoming/incomingrequest/010.php | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index d1fad9b7724f..ab79d6c149d8 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -182,14 +182,13 @@ The second and third parameters match up to the ``$depth`` and ``$flags`` argume Getting Specific Data from JSON =============================== -You can get a specific piece of data from a JSON stream by passing a variable name into ``getVar()`` for the +You can get a specific piece of data from a JSON stream by passing a variable name into ``getJsonVar()`` for the data that you want or you can use "dot" notation to dig into the JSON to get data that is not on the root level. .. literalinclude:: incomingrequest/010.php -If you want the result to be an associative array instead of an object, you can use ``getJsonVar()`` instead and pass -true in the second parameter. This function can also be used if you can't guarantee that the incoming request will have the -correct ``Content-Type`` header. +If you want the result to be an associative array instead of an object, you can +pass true in the second parameter: .. literalinclude:: incomingrequest/011.php diff --git a/user_guide_src/source/incoming/incomingrequest/010.php b/user_guide_src/source/incoming/incomingrequest/010.php index a199c91bffe2..cf9824d8cd6e 100644 --- a/user_guide_src/source/incoming/incomingrequest/010.php +++ b/user_guide_src/source/incoming/incomingrequest/010.php @@ -10,8 +10,8 @@ * } */ -$data = $request->getVar('foo'); +$data = $request->getJsonVar('foo'); // $data = "bar" -$data = $request->getVar('fizz.buzz'); +$data = $request->getJsonVar('fizz.buzz'); // $data = "baz" From e3c0edcda4cd10bf9f523cc5585078e7b4af4c0c Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:44:24 +0900 Subject: [PATCH 15/18] docs: replace `here` with meaningful text The anchor text `here` is not recommened. --- .../source/incoming/incomingrequest.rst | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index ab79d6c149d8..f2d8d02f8cf2 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -355,10 +355,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getVar([$index = null[, $filter = null[, $flags = null]]]) :param string $index: The name of the variable/key to look for. - :param int $filter: The type of filter to apply. A list of filters can be found - `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_REQUEST`` if no parameters supplied, otherwise the REQUEST value if found, or null if not :rtype: array|bool|float|int|object|string|null @@ -367,10 +367,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getGet([$index = null[, $filter = null[, $flags = null]]]) :param string $index: The name of the variable/key to look for. - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_GET`` if no parameters supplied, otherwise the GET value if found, or null if not :rtype: array|bool|float|int|object|string|null @@ -418,10 +418,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getPostGet([$index = null[, $filter = null[, $flags = null]]]) :param string $index: The name of the variable/key to look for. - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_POST`` and ``$_GET`` combined if no parameters specified (prefer POST value on conflict), otherwise looks for POST value, if nothing found looks for GET value, if no value found returns null :rtype: array|bool|float|int|object|string|null @@ -438,10 +438,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getGetPost([$index = null[, $filter = null[, $flags = null]]]) :param string $index: The name of the variable/key to look for. - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_GET`` and ``$_POST`` combined if no parameters specified (prefer GET value on conflict), otherwise looks for GET value, if nothing found looks for POST value, if no value found returns null :rtype: array|bool|float|int|object|string|null @@ -458,10 +458,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getCookie([$index = null[, $filter = null[, $flags = null]]]) :param array|string|null $index: COOKIE name - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_COOKIE`` if no parameters supplied, otherwise the COOKIE value if found or null if not :rtype: array|bool|float|int|object|string|null @@ -480,10 +480,10 @@ The methods provided by the parent classes that are available are: .. php:method:: getServer([$index = null[, $filter = null[, $flags = null]]]) :param array|string|null $index: Value name - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. - :param int $flags: Flags to apply. A list of flags can be found - `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. + :param int $flags: Flags to apply. A list of flags can be found in + `Filter flags `__. :returns: ``$_SERVER`` item value if found, null if not :rtype: array|bool|float|int|object|string|null @@ -499,8 +499,8 @@ The methods provided by the parent classes that are available are: .. php:method:: getUserAgent([$filter = null]) - :param int $filter: The type of filter to apply. A list of filters can be - found `here `__. + :param int $filter: The type of filter to apply. A list of filters can be found in + `Types of filters `__. :returns: The User Agent string, as found in the SERVER data, or null if not found. :rtype: CodeIgniter\\HTTP\\UserAgent From 99538c553c789d5b2415b18a7fdf2541927272c2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:45:38 +0900 Subject: [PATCH 16/18] docs: fix incorrect param There is no param in getUserAgent(). --- user_guide_src/source/incoming/incomingrequest.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index f2d8d02f8cf2..c3f5f7495073 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -497,10 +497,8 @@ The methods provided by the parent classes that are available are: .. literalinclude:: incomingrequest/037.php - .. php:method:: getUserAgent([$filter = null]) + .. php:method:: getUserAgent() - :param int $filter: The type of filter to apply. A list of filters can be found in - `Types of filters `__. :returns: The User Agent string, as found in the SERVER data, or null if not found. :rtype: CodeIgniter\\HTTP\\UserAgent From fb0af42345619fec3f2f76c3b1f0370b9a037f5f Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 09:56:59 +0900 Subject: [PATCH 17/18] docs: add note to not recommended method --- user_guide_src/source/incoming/incomingrequest.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index c3f5f7495073..479e64e18278 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -151,6 +151,10 @@ getGetPost() getVar() -------- +.. important:: This method exists only for backward compatibility. Do not use it + in new projects. Even if you are already using it, we recommend that you use + another, more appropriate method. + The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data from ``$_GET``, ``$POST``, or ``$_COOKIE`` (depending on php.ini `request-order `_). .. warning:: If you want to validate POST data only, don't use ``getVar()``. @@ -362,6 +366,10 @@ The methods provided by the parent classes that are available are: :returns: ``$_REQUEST`` if no parameters supplied, otherwise the REQUEST value if found, or null if not :rtype: array|bool|float|int|object|string|null + .. important:: This method exists only for backward compatibility. Do not use it + in new projects. Even if you are already using it, we recommend that you use + another, more appropriate method. + This method is identical to ``getGet()``, only it fetches REQUEST data. .. php:method:: getGet([$index = null[, $filter = null[, $flags = null]]]) From b8871133e0482cebbe83d748f6d64c026d3256c7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 Nov 2023 06:52:10 +0900 Subject: [PATCH 18/18] docs: fix description Co-authored-by: Michal Sniatala --- user_guide_src/source/incoming/incomingrequest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 479e64e18278..c6db5b28fe4c 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -396,7 +396,7 @@ The methods provided by the parent classes that are available are: To return an array of all GET items call without any parameters. - To return all REQUEST items and pass them through the filter, set the + To return all GET items and pass them through the filter, set the first parameter to null while setting the second parameter to the filter you want to use: