Skip to content

Commit ed1dfda

Browse files
authored
Merge pull request #9097 from kenjis/docs-model-validation
docs: improve In-Model Validation
2 parents 078d4c1 + 0630332 commit ed1dfda

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

user_guide_src/source/libraries/validation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ the validation rules.
476476
.. literalinclude:: validation/045.php
477477
:lines: 2-
478478

479+
.. _saving-validation-rules-to-config-file:
480+
479481
Saving Sets of Validation Rules to the Config File
480482
==================================================
481483

@@ -875,6 +877,8 @@ Or you can use the following parameters:
875877
.. literalinclude:: validation/047.php
876878
:lines: 2-
877879

880+
.. _validation-available-rules:
881+
878882
***************
879883
Available Rules
880884
***************

user_guide_src/source/models/model.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ $validationRules
243243

244244
Contains either an array of validation rules as described in :ref:`validation-array`
245245
or a string containing the name of a validation group, as described in the same section.
246-
Described in more detail below.
246+
See also :ref:`model-setting-validation-rules`.
247247

248248
$validationMessages
249249
^^^^^^^^^^^^^^^^^^^
250250

251251
Contains an array of custom error messages that should be used during validation, as
252-
described in :ref:`validation-custom-errors`. Described in more detail below.
252+
described in :ref:`validation-custom-errors`. See also :ref:`model-setting-validation-rules`.
253253

254254
$skipValidation
255255
^^^^^^^^^^^^^^^
@@ -649,11 +649,14 @@ Cleans out the database table by permanently removing all rows that have 'delete
649649
In-Model Validation
650650
===================
651651

652+
.. warning:: In-Model validation is performed just before data is stored in the
653+
database. Prior to that point, the data has not yet been validated. Processing
654+
user-input data prior to validation may introduce vulnerabilities.
655+
652656
Validating Data
653657
---------------
654658

655-
For many people, validating data in the model is the preferred way to ensure the data is kept to a single
656-
standard, without duplicating code. The Model class provides a way to automatically have all data validated
659+
The Model class provides a way to automatically have all data validated
657660
prior to saving to the database with the ``insert()``, ``update()``, or ``save()`` methods.
658661

659662
.. important:: When you update data, by default, the validation in the model class only
@@ -668,16 +671,24 @@ prior to saving to the database with the ``insert()``, ``update()``, or ``save()
668671
To avoid such glitches, this behavior can be changed by configuration. See
669672
:ref:`clean-validation-rules` for details.
670673

674+
.. _model-setting-validation-rules:
675+
671676
Setting Validation Rules
672677
------------------------
673678

674-
The first step is to fill out the `$validationRules`_ class property with the fields and rules that should
675-
be applied. If you have custom error message that you want to use, place them in the `$validationMessages`_ array:
679+
The first step is to fill out the `$validationRules`_ class property with the
680+
fields and rules that should be applied.
681+
682+
.. note:: You can see the list of built-in Validation rules in :ref:`validation-available-rules`.
683+
684+
If you have custom error message that you want to use, place them in the `$validationMessages`_ array:
676685

677686
.. literalinclude:: model/027.php
678687

679-
If you'd rather organize your rules and error messages within the Validation configuration file, you can do that
680-
and simply set `$validationRules`_ to the name of the validation rule group you created:
688+
If you'd rather organize your rules and error messages within the
689+
:ref:`Validation Config File <saving-validation-rules-to-config-file>`, you can
690+
do that and simply set `$validationRules`_ to the name of the validation rule
691+
group you created:
681692

682693
.. literalinclude:: model/034.php
683694

0 commit comments

Comments
 (0)