Skip to content

Commit 62b570f

Browse files
authored
Merge pull request #8550 from kenjis/docs-replace-controller-validate
docs: replace `$this->validate()` with `validateData()`
2 parents 872025d + 53f82f3 commit 62b570f

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

user_guide_src/source/installation/upgrade_file_upload/001.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function index()
1111

1212
public function do_upload()
1313
{
14-
$this->validate([
14+
$this->validateData([], [
1515
'userfile' => [
1616
'uploaded[userfile]',
1717
'max_size[userfile,100]',

user_guide_src/source/installation/upgrade_validations.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ Upgrade Guide
3232

3333
2. Within the controller you have to change the following:
3434

35-
- ``$this->load->helper(array('form', 'url'));`` to ``helper(['form', 'url']);``
35+
- ``$this->load->helper(array('form', 'url'));`` to ``helper('form');``
3636
- remove the line ``$this->load->library('form_validation');``
37-
- ``if ($this->form_validation->run() == FALSE)`` to ``if (! $this->validate([]))``
37+
- ``if ($this->form_validation->run() == FALSE)`` to ``if (! $this->validateData($data, $rules))``
38+
where ``$data`` is the data to validate, typically, the POST data ``$this->request->getPost()``.
3839
- ``$this->load->view('myform');`` to ``return view('myform', ['validation' => $this->validator,]);``
3940

4041
3. You have to change the validation rules. The new syntax is to set the rules as array in the controller:

user_guide_src/source/installation/upgrade_validations/001.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$isValid = $this->validate([
3+
$isValid = $this->validateData($data, [
44
'name' => 'required|min_length[3]',
55
'email' => 'required|valid_email',
66
'phone' => 'required|numeric|max_length[10]',

user_guide_src/source/installation/upgrade_validations/002.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ class Form extends Controller
88
{
99
public function index()
1010
{
11-
helper(['form', 'url']);
11+
helper('form');
1212

13-
if (! $this->validate([
13+
$data = $this->request->getPost();
14+
15+
if (! $this->validateData($data, [
1416
// Validation rules
1517
])) {
1618
return view('myform');

user_guide_src/source/libraries/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ file upload related rules::
998998
<input type="file" name="avatar">
999999

10001000
// In the controller
1001-
$this->validate([
1001+
$this->validateData([], [
10021002
'avatar' => 'uploaded[avatar]|max_size[avatar,1024]',
10031003
]);
10041004

user_guide_src/source/libraries/validation/045.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// In Controller.
44

5-
if (! $this->validate([
5+
if (! $this->validateData($data, [
66
'username' => 'required',
77
'password' => 'required|min_length[10]',
88
])) {

0 commit comments

Comments
 (0)