Skip to content

Commit adf2dc6

Browse files
authored
Merge pull request #6194 from kenjis/fix-docs-Validation-setRules
docs: add sample code for array validation rules
2 parents 949bed6 + 2217a4f commit adf2dc6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

tests/system/Validation/ValidationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ public function testRulesSetup($rules, $expected, array $errors = [])
440440
$data = ['foo' => ''];
441441
$this->validation->setRules(['foo' => $rules], $errors);
442442
$this->validation->run($data);
443+
443444
$this->assertSame($expected, $this->validation->getError('foo'));
444445
}
445446

@@ -468,13 +469,24 @@ public function rulesSetupProvider(): Generator
468469
['rules' => 'min_length[10]'],
469470
'The foo field must be at least 10 characters in length.',
470471
],
472+
[
473+
['rules' => ['min_length[10]']],
474+
'The foo field must be at least 10 characters in length.',
475+
],
471476
[
472477
[
473478
'label' => 'Foo Bar',
474479
'rules' => 'min_length[10]',
475480
],
476481
'The Foo Bar field must be at least 10 characters in length.',
477482
],
483+
[
484+
[
485+
'label' => 'Foo Bar',
486+
'rules' => ['min_length[10]'],
487+
],
488+
'The Foo Bar field must be at least 10 characters in length.',
489+
],
478490
[
479491
[
480492
'label' => 'Foo Bar',

user_guide_src/source/libraries/validation/006.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
'username' => 'required',
55
'password' => 'required|min_length[10]',
66
]);
7+
// or
8+
$validation->setRules([
9+
'username' => 'required',
10+
'password' => ['required', 'min_length[10]'],
11+
]);

user_guide_src/source/libraries/validation/007.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
'username' => ['label' => 'Username', 'rules' => 'required'],
55
'password' => ['label' => 'Password', 'rules' => 'required|min_length[10]'],
66
]);
7+
// or
8+
$validation->setRules([
9+
'username' => ['label' => 'Username', 'rules' => 'required'],
10+
'password' => ['label' => 'Password', 'rules' => ['required', 'min_length[10]']],
11+
]);

0 commit comments

Comments
 (0)