From 6b78a75c431fc3495b0ae030a3401c2790f944bf Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 Nov 2023 11:22:32 +0900 Subject: [PATCH] docs: use validateData() instead of validate() validate() is not recommended. --- .../source/tutorial/create_news_items.rst | 13 ++++++++++++- .../source/tutorial/create_news_items/005.php | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index 6443e674d450..6f2c5f997c6e 100644 --- a/user_guide_src/source/tutorial/create_news_items.rst +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -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() ` to validate the submitted data. +Next, you'll use the Controller-provided helper function +:ref:`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>`. diff --git a/user_guide_src/source/tutorial/create_news_items/005.php b/user_guide_src/source/tutorial/create_news_items/005.php index 6d565789141a..bf3a3e2b3bb0 100644 --- a/user_guide_src/source/tutorial/create_news_items/005.php +++ b/user_guide_src/source/tutorial/create_news_items/005.php @@ -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]', ])) {