Skip to content

Commit

Permalink
Merge pull request #8550 from kenjis/docs-replace-controller-validate
Browse files Browse the repository at this point in the history
docs: replace `$this->validate()` with `validateData()`
  • Loading branch information
kenjis authored Feb 17, 2024
2 parents 872025d + 53f82f3 commit 62b570f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function index()

public function do_upload()
{
$this->validate([
$this->validateData([], [
'userfile' => [
'uploaded[userfile]',
'max_size[userfile,100]',
Expand Down
5 changes: 3 additions & 2 deletions user_guide_src/source/installation/upgrade_validations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Upgrade Guide

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

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

3. You have to change the validation rules. The new syntax is to set the rules as array in the controller:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$isValid = $this->validate([
$isValid = $this->validateData($data, [
'name' => 'required|min_length[3]',
'email' => 'required|valid_email',
'phone' => 'required|numeric|max_length[10]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class Form extends Controller
{
public function index()
{
helper(['form', 'url']);
helper('form');

if (! $this->validate([
$data = $this->request->getPost();

if (! $this->validateData($data, [
// Validation rules
])) {
return view('myform');
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ file upload related rules::
<input type="file" name="avatar">

// In the controller
$this->validate([
$this->validateData([], [
'avatar' => 'uploaded[avatar]|max_size[avatar,1024]',
]);

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/libraries/validation/045.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// In Controller.

if (! $this->validate([
if (! $this->validateData($data, [
'username' => 'required',
'password' => 'required|min_length[10]',
])) {
Expand Down

0 comments on commit 62b570f

Please sign in to comment.