Skip to content

Commit a859ba0

Browse files
authored
Merge pull request #8172 from kenjis/docs-tutorial-use-validatedata
docs: use validateData() instead of validate() in Tutorial
2 parents 9c4e051 + 6b78a75 commit a859ba0

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

user_guide_src/source/tutorial/create_news_items.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,22 @@ You're going to do three things here:
106106

107107
The code above adds a lot of functionality.
108108

109+
Retrieve the Data
110+
^^^^^^^^^^^^^^^^^
111+
112+
First, we use the :doc:`IncomingRequest <../incoming/incomingrequest>`
113+
object ``$this->request``, which is set in the controller by the framework.
114+
115+
We get the necessary items from the **POST** data by the user and set them in the
116+
``$data`` variable.
117+
109118
Validate the Data
110119
^^^^^^^^^^^^^^^^^
111120

112-
You'll use the Controller-provided helper function :ref:`validate() <controller-validate>` to validate the submitted data.
121+
Next, you'll use the Controller-provided helper function
122+
:ref:`validateData() <controller-validatedata>` to validate the submitted data.
113123
In this case, the title and body fields are required and in the specific length.
124+
114125
CodeIgniter has a powerful validation library as demonstrated
115126
above. You can read more about the :doc:`Validation library <../libraries/validation>`.
116127

user_guide_src/source/tutorial/create_news_items/005.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ public function create()
1313
{
1414
helper('form');
1515

16+
$data = $this->request->getPost(['title', 'body']);
17+
1618
// Checks whether the submitted data passed the validation rules.
17-
if (! $this->validate([
19+
if (! $this->validateData($data, [
1820
'title' => 'required|max_length[255]|min_length[3]',
1921
'body' => 'required|max_length[5000]|min_length[10]',
2022
])) {

0 commit comments

Comments
 (0)