Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use validateData() instead of validate() in Tutorial #8172

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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