Skip to content

Commit c6f3a67

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
Conflicts: user_guide_src/source/tutorial/news_section.rst
2 parents d169485 + 197e996 commit c6f3a67

12 files changed

Lines changed: 97 additions & 27 deletions

File tree

user_guide_src/source/changelogs/v4.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Commands
118118
Others
119119
======
120120

121+
- Added ``$this->validateData()`` in Controller. See :ref:`controller-validatedata`.
121122
- Content Security Policy (CSP) enhancements
122123
- Added the configs ``$scriptNonceTag`` and ``$styleNonceTag`` in ``Config\ContentSecurityPolicy`` to customize the CSP placeholders (``{csp-script-nonce}`` and ``{csp-style-nonce}``)
123124
- Added the config ``$autoNonce`` in ``Config\ContentSecurityPolicy`` to disable the CSP placeholder replacement

user_guide_src/source/concepts/mvc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Views are generally stored in **app/Views**, but can quickly become unwieldy if
5151
CodeIgniter does not enforce any type of organization, but a good rule of thumb would be to create a new directory in
5252
the **Views** directory for each controller. Then, name views by the method name. This makes them very easy to find later
5353
on. For example, a user's profile might be displayed in a controller named ``User``, and a method named ``profile``.
54-
You might store the view file for this method in **app/Views/User/Profile.php**.
54+
You might store the view file for this method in **app/Views/user/profile.php**.
5555

5656
That type of organization works great as a base habit to get into. At times you might need to organize it differently.
5757
That's not a problem. As long as CodeIgniter can find the file, it can display it.

user_guide_src/source/database/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Database Configuration
66
:local:
77
:depth: 2
88

9+
.. note::
10+
See :ref:`requirements-supported-databases` for currently supported database drivers.
11+
912
***********
1013
Config File
1114
***********

user_guide_src/source/general/helpers.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ global **system/Helpers** directory.
3232
Loading a Helper
3333
================
3434

35+
.. note:: The URL helper is always loaded so you do not need to load it yourself.
36+
3537
Loading a helper file is quite simple using the following method:
3638

3739
.. literalinclude:: helpers/001.php
@@ -44,22 +46,31 @@ For example, to load the **Cookie Helper** file, which is named
4446

4547
.. literalinclude:: helpers/002.php
4648

49+
.. note:: The Helper loading method above does not return a value, so
50+
don't try to assign it to a variable. Just use it as shown.
51+
52+
Loading Multiple Helpers
53+
------------------------
54+
4755
If you need to load more than one helper at a time, you can pass
4856
an array of file names in and all of them will be loaded:
4957

5058
.. literalinclude:: helpers/003.php
5159

60+
Loading in a Controller
61+
-----------------------
62+
5263
A helper can be loaded anywhere within your controller methods (or
5364
even within your View files, although that's not a good practice), as
54-
long as you load it before you use it. You can load your helpers in your
65+
long as you load it before you use it.
66+
67+
You can load your helpers in your
5568
controller constructor so that they become available automatically in
56-
any function, or you can load a helper in a specific function that needs
69+
any method, or you can load a helper in a specific method that needs
5770
it.
5871

59-
.. note:: The Helper loading method above does not return a value, so
60-
don't try to assign it to a variable. Just use it as shown.
61-
62-
.. note:: The URL helper is always loaded so you do not need to load it yourself.
72+
However if you want to load in your controller constructor, you can use the ``$helpers``
73+
property in Controller instead. See :ref:`Controllers <controllers-helpers>`.
6374

6475
Loading from Non-standard Locations
6576
-----------------------------------
@@ -73,9 +84,9 @@ sub-directory named **Helpers**. An example will help understand this.
7384

7485
For this example, assume that we have grouped together all of our Blog-related
7586
code into its own namespace, ``Example\Blog``. The files exist on our server at
76-
**/Modules/Blog/**. So, we would put our Helper files for the blog module in
77-
**/Modules/Blog/Helpers/**. A **blog_helper** file would be at
78-
**/Modules/Blog/Helpers/blog_helper.php**. Within our controller we could
87+
**Modules/Blog/**. So, we would put our Helper files for the blog module in
88+
**Modules/Blog/Helpers/**. A **blog_helper** file would be at
89+
**Modules/Blog/Helpers/blog_helper.php**. Within our controller we could
7990
use the following command to load the helper for us:
8091

8192
.. literalinclude:: helpers/004.php
@@ -101,7 +112,7 @@ Using a Helper
101112
Once you've loaded the Helper File containing the function you intend to
102113
use, you'll call it the way you would a standard PHP function.
103114

104-
For example, to create a link using the ``anchor()`` function in one of
115+
For example, to create a link using the :php:func:`anchor()` function in one of
105116
your view files you would do this:
106117

107118
.. literalinclude:: helpers/005.php
@@ -131,7 +142,7 @@ functions:
131142

132143
.. literalinclude:: helpers/006.php
133144

134-
The ``helper()`` method will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
145+
The ``helper()`` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
135146
and load in ALL matching helpers of the same name. This allows any module's helpers
136147
to be loaded, as well as any helpers you've created specifically for this application. The load order
137148
is as follows:

user_guide_src/source/incoming/controllers.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ Included Properties
3535

3636
The CodeIgniter's Controller provides these properties.
3737

38-
**Request Object**
38+
Request Object
39+
==============
3940

4041
The application's main :doc:`Request Instance </incoming/incomingrequest>` is always available
4142
as a class property, ``$this->request``.
4243

43-
**Response Object**
44+
Response Object
45+
===============
4446

4547
The application's main :doc:`Response Instance </outgoing/response>` is always available
4648
as a class property, ``$this->response``.
4749

48-
**Logger Object**
50+
Logger Object
51+
=============
4952

5053
An instance of the :doc:`Logger <../general/logging>` class is available as a class property,
5154
``$this->logger``.
5255

56+
.. _controllers-helpers:
57+
5358
Helpers
5459
=======
5560

@@ -79,7 +84,7 @@ modify this by passing the duration (in seconds) as the first parameter:
7984

8085
.. _controller-validate:
8186

82-
Validating data
87+
Validating Data
8388
***************
8489

8590
$this->validate()
@@ -90,6 +95,15 @@ The method accepts an array of rules in the first parameter,
9095
and in the optional second parameter, an array of custom error messages to display
9196
if the items are not valid. Internally, this uses the controller's
9297
``$this->request`` instance to get the data to be validated.
98+
99+
.. warning::
100+
The ``validate()`` method uses :ref:`Validation::withRequest() <validation-withrequest>` method.
101+
It validates data from :ref:`$request->getJSON() <incomingrequest-getting-json-data>`
102+
or :ref:`$request->getRawInput() <incomingrequest-retrieving-raw-data>`
103+
or :ref:`$request->getVar() <incomingrequest-getting-data>`.
104+
Which data is used depends on the request. Remember that an attacker is free to send any request to
105+
the server.
106+
93107
The :doc:`Validation Library docs </libraries/validation>` have details on
94108
rule and message array formats, as well as available rules:
95109

@@ -107,6 +121,8 @@ the ``$rules`` array with the name of the group as defined in **app/Config/Valid
107121
$this->validateData()
108122
=====================
109123

124+
.. versionadded:: 4.2.0
125+
110126
Sometimes you may want to check the controller method parameters or other custom data.
111127
In that case, you can use the ``$this->validateData()`` method.
112128
The method accepts an array of data to validate in the first parameter:

user_guide_src/source/incoming/controllers/006.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public function product(int $id)
1717
];
1818

1919
if (! $this->validateData($data, $rule)) {
20-
// ...
20+
return view('store/product', [
21+
'errors' => $this->validator->getErrors(),
22+
]);
2123
}
2224

2325
// ...

user_guide_src/source/incoming/incomingrequest.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ With CodeIgniter's built-in methods you can simply do this:
8080

8181
.. literalinclude:: incomingrequest/008.php
8282

83+
.. _incomingrequest-getting-data:
84+
8385
Getting Data
8486
============
8587

8688
The ``getVar()`` method will pull from ``$_REQUEST``, so will return any data from ``$_GET``, ``$POST``, or ``$_COOKIE`` (depending on php.ini `request-order <https://www.php.net/manual/en/ini.core.php#ini.request-order>`_).
8789

88-
.. note:: If the incoming request has a ``CONTENT_TYPE`` header set to ``application/json``,
90+
.. note:: If the incoming request has a ``Content-Type`` header set to ``application/json``,
8991
the ``getVar()`` method returns the JSON data instead of ``$_REQUEST`` data.
9092

9193
While this
@@ -103,6 +105,8 @@ maintaining the ability to control the order you look for it:
103105
* ``$request->getPostGet()`` - checks ``$_POST`` first, then ``$_GET``
104106
* ``$request->getGetPost()`` - checks ``$_GET`` first, then ``$_POST``
105107

108+
.. _incomingrequest-getting-json-data:
109+
106110
Getting JSON Data
107111
=================
108112

@@ -119,7 +123,7 @@ arrays, pass in ``true`` as the first parameter.
119123
The second and third parameters match up to the ``depth`` and ``options`` arguments of the
120124
`json_decode <https://www.php.net/manual/en/function.json-decode.php>`_ PHP function.
121125

122-
If the incoming request has a ``CONTENT_TYPE`` header set to ``application/json``, you can also use ``getVar()`` to get
126+
If the incoming request has a ``Content-Type`` header set to ``application/json``, you can also use ``getVar()`` to get
123127
the JSON stream. Using ``getVar()`` in this way will always return an object.
124128

125129
Getting Specific Data from JSON
@@ -132,12 +136,14 @@ data that you want or you can use "dot" notation to dig into the JSON to get dat
132136

133137
If you want the result to be an associative array instead of an object, you can use ``getJsonVar()`` instead and pass
134138
true in the second parameter. This function can also be used if you can't guarantee that the incoming request will have the
135-
correct ``CONTENT_TYPE`` header.
139+
correct ``Content-Type`` header.
136140

137141
.. literalinclude:: incomingrequest/011.php
138142

139143
.. note:: See the documentation for :php:func:`dot_array_search()` in the ``Array`` helper for more information on "dot" notation.
140144

145+
.. _incomingrequest-retrieving-raw-data:
146+
141147
Retrieving Raw Data (PUT, PATCH, DELETE)
142148
========================================
143149

user_guide_src/source/installation/installing_composer.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ Read the :doc:`upgrade instructions <upgrading>`, and check Breaking Changes and
7272
Pros
7373
----
7474

75-
Simple installation; easy to update
75+
Simple installation; easy to update.
7676

7777
Cons
7878
----
7979

80-
You still need to check for ``app/Config`` changes after updating
80+
You still need to check for file changes in the **project space**
81+
(root, app, public, writable) after updating.
8182

8283
Structure
8384
---------
@@ -155,12 +156,13 @@ Read the :doc:`upgrade instructions <upgrading>`, and check Breaking Changes and
155156
Pros
156157
----
157158

158-
Relatively simple installation; easy to update
159+
Relatively simple installation; easy to update.
159160

160161
Cons
161162
----
162163

163-
You still need to check for ``app/Config`` changes after updating
164+
You still need to check for file changes in the **project space**
165+
(root, app, public, writable) after updating.
164166

165167
Structure
166168
---------

user_guide_src/source/installation/installing_manual.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ Read the :doc:`upgrade instructions <upgrading>`, and check Breaking Changes and
4444
Pros
4545
====
4646

47-
Download and run
47+
Download and run.
4848

4949
Cons
5050
====
5151

52-
You are responsible for merge conflicts when updating
52+
You are responsible for merge conflicts when updating.
5353

5454
Structure
5555
=========

user_guide_src/source/intro/requirements.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
Server Requirements
33
###################
44

5+
.. contents::
6+
:local:
7+
:depth: 2
8+
9+
***************************
10+
PHP and Required Extensions
11+
***************************
12+
513
`PHP <https://www.php.net/>`_ version 7.4 or newer is required, with the following PHP extensions are enabled:
614

715
- `intl <https://www.php.net/manual/en/intl.requirements.php>`_
816
- `mbstring <https://www.php.net/manual/en/mbstring.requirements.php>`_
917
- `json <https://www.php.net/manual/en/json.requirements.php>`_
1018

19+
***********************
20+
Optional PHP Extensions
21+
***********************
22+
1123
The following PHP extensions should be enabled on your server:
1224

1325
- `mysqlnd <https://www.php.net/manual/en/mysqlnd.install.php>`_ (if you use MySQL)
@@ -28,6 +40,12 @@ The following PHP extensions are required when you use PHPUnit:
2840
- `libxml <https://www.php.net/manual/en/libxml.requirements.php>`_ (if you use :doc:`TestResponse </testing/response>` class)
2941
- `xdebug <https://xdebug.org/docs/install>`_ (if you use ``CIUnitTestCase::assertHeaderEmitted()``)
3042

43+
.. _requirements-supported-databases:
44+
45+
*******************
46+
Supported Databases
47+
*******************
48+
3149
A database is required for most web application programming.
3250
Currently supported databases are:
3351

0 commit comments

Comments
 (0)