Skip to content

Commit

Permalink
docs: use validateData() instead of validate()
Browse files Browse the repository at this point in the history
validate() is not recommended.
  • Loading branch information
kenjis committed Nov 8, 2023
1 parent 99ef79b commit 6b78a75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion user_guide_src/source/tutorial/create_news_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,22 @@ You're going to do three things here:

The code above adds a lot of functionality.

Retrieve the Data
^^^^^^^^^^^^^^^^^

First, we use the :doc:`IncomingRequest <../incoming/incomingrequest>`
object ``$this->request``, which is set in the controller by the framework.

We get the necessary items from the **POST** data by the user and set them in the
``$data`` variable.

Validate the Data
^^^^^^^^^^^^^^^^^

You'll use the Controller-provided helper function :ref:`validate() <controller-validate>` to validate the submitted data.
Next, you'll use the Controller-provided helper function
:ref:`validateData() <controller-validatedata>` to validate the submitted data.
In this case, the title and body fields are required and in the specific length.

CodeIgniter has a powerful validation library as demonstrated
above. You can read more about the :doc:`Validation library <../libraries/validation>`.

Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/tutorial/create_news_items/005.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public function create()
{
helper('form');

$data = $this->request->getPost(['title', 'body']);

// Checks whether the submitted data passed the validation rules.
if (! $this->validate([
if (! $this->validateData($data, [
'title' => 'required|max_length[255]|min_length[3]',
'body' => 'required|max_length[5000]|min_length[10]',
])) {
Expand Down

0 comments on commit 6b78a75

Please sign in to comment.