Skip to content

Commit f8cc7e6

Browse files
authored
Merge pull request #7209 from kenjis/docs-improve-validation
docs: update validation.rst
2 parents 52c4464 + d7c0af7 commit f8cc7e6

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

user_guide_src/source/libraries/validation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,13 @@ shown above. The primary benefit here is that it provides some extra navigation
603603
Creating a Rule Class
604604
---------------------
605605

606-
Within the file itself, each method is a rule and must accept a string as the first parameter, and must return
606+
Within the file itself, each method is a rule and must accept a value to validate as the first parameter, and must return
607607
a boolean true or false value signifying true if it passed the test or false if it did not:
608608

609609
.. literalinclude:: validation/034.php
610610

611611
By default, the system will look within ``CodeIgniter\Language\en\Validation.php`` for the language strings used
612-
within errors. In custom rules, you may provide error messages by accepting a ``$error`` variable by reference in the
612+
within errors. In custom rules, you may provide error messages by accepting a ``&$error`` variable by reference in the
613613
second parameter:
614614

615615
.. literalinclude:: validation/035.php
@@ -624,13 +624,13 @@ Your new custom rule could now be used just like any other rule:
624624
Allowing Parameters
625625
-------------------
626626

627-
If your method needs to work with parameters, the function will need a minimum of three parameters: the string to validate,
627+
If your method needs to work with parameters, the function will need a minimum of three parameters: the value to validate,
628628
the parameter string, and an array with all of the data that was submitted the form. The ``$data`` array is especially handy
629629
for rules like ``required_with`` that needs to check the value of another submitted field to base its result on:
630630

631631
.. literalinclude:: validation/037.php
632632

633-
Custom errors can be returned as the fourth parameter, just as described above.
633+
Custom errors can be returned as the fourth parameter ``&$error``, just as described above.
634634

635635
.. _validation-using-closure-rule:
636636

user_guide_src/source/libraries/validation/034.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class MyRules
44
{
5-
public function even(string $str): bool
5+
public function even($value): bool
66
{
7-
return (int) $str % 2 === 0;
7+
return (int) $value % 2 === 0;
88
}
99
}

user_guide_src/source/libraries/validation/035.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
class MyRules
44
{
5-
public function even(string $str, ?string &$error = null): bool
5+
public function even($value, ?string &$error = null): bool
66
{
7-
if ((int) $str % 2 !== 0) {
7+
if ((int) $value % 2 !== 0) {
88
$error = lang('myerrors.evenError');
99

1010
return false;

user_guide_src/source/libraries/validation/037.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
class MyRules
44
{
5-
public function required_with($str, string $fields, array $data): bool
5+
public function required_with($value, string $params, array $data): bool
66
{
7-
$fields = explode(',', $fields);
7+
$params = explode(',', $params);
88

99
// If the field is present we can safely assume that
1010
// the field is here, no matter whether the corresponding
1111
// search field is present or not.
12-
$present = $this->required($str ?? '');
12+
$present = $this->required($value ?? '');
1313

1414
if ($present) {
1515
return true;
@@ -20,7 +20,7 @@ public function required_with($str, string $fields, array $data): bool
2020
// as $fields is the lis
2121
$requiredFields = [];
2222

23-
foreach ($fields as $field) {
23+
foreach ($params as $field) {
2424
if (array_key_exists($field, $data)) {
2525
$requiredFields[] = $field;
2626
}

0 commit comments

Comments
 (0)