From 42773de14de20e6192ccdfdfb1023ec3c1e8626f Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 10:35:30 +0900 Subject: [PATCH 01/13] docs: add param type --- user_guide_src/source/outgoing/view_cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index aefdb2339d28..a88343e5ecdc 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -42,7 +42,7 @@ Simple Cells are classes that return a string from the chosen method. An example class AlertMessage { - public function show($params): string + public function show(array $params): string { return "
{$params['message']}
"; } From 919b7280f65fd2a81bd1898e8704464279b7a613 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 10:35:50 +0900 Subject: [PATCH 02/13] docs: move versionadded --- user_guide_src/source/outgoing/view_cells.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index a88343e5ecdc..36553ad6655b 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -74,6 +74,8 @@ When you use it this way, all of the parameters must always be specified in the Controlled Cells **************** +.. versionadded:: 4.3.0 + Controlled Cells have two primary goals: to make it as fast as possible to build the cell, and provide additional logic and flexibility to your views, if they need it. The class must extend ``CodeIgniter\View\Cells\Cell``. They should have a view file in the same folder. By convention the class name should be PascalCase and the view should be the snake_cased version of the class name. So, for example, if you have a ``MyCell`` class, the view file should be ``my_cell.php``. Creating a Controlled Cell @@ -103,8 +105,6 @@ At the most basic level, all you need to implement within the class are public p Generating Cell via Command =========================== -.. versionadded:: 4.3.0 - You can also create a controlled cell via a built in command from the CLI. The command is ``php spark make:cell``. It takes one argument, the name of the cell to create. The name should be in PascalCase, and the class will be created in the ``app/Cells`` directory. The view file will also be created in the ``app/Cells`` directory. :: From 552ad9edd8f82864647bf6f8b057e7a0ffdbd73d Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 10:36:20 +0900 Subject: [PATCH 03/13] docs: fix incorrect explanation --- user_guide_src/source/outgoing/view_cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 36553ad6655b..3d9cf283cf00 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -21,7 +21,7 @@ No matter which type of View Cell you are using, you can call it from any view b 'value1', 'param2' => 'value2']); ?> -If you do not include the full namespace for the class, it will assume in can be found in the ``App\Cells`` namespace. So, the above example would attempt to find the ``MyClass`` class in ``app/Cells/MyClass.php``. If it is not found there, all namespaces will be scanned until it is found, searching within a ``Cells`` subdirectory of each namespace. +If you do not include the full namespace for the class, it will assume in can be found in the ``App\Cells`` namespace. So, the following example would attempt to find the ``MyClass`` class in ``app/Cells/MyClass.php``. If it is not found there, all namespaces will be scanned until it is found, searching within a ``Cells`` subdirectory of each namespace. :: 'value1', 'param2' => 'value2']); ?> From a74db618bd64998a2ccc1c0ce9dc043ea1faf410 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 10:36:47 +0900 Subject: [PATCH 04/13] docs: add note for the new feature --- user_guide_src/source/outgoing/view_cells.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 3d9cf283cf00..0c6541984b8e 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -26,6 +26,8 @@ If you do not include the full namespace for the class, it will assume in can be 'value1', 'param2' => 'value2']); ?> +.. note:: Namespace omission is available since v4.3.0 and later. + You can also pass the parameters along as a key/value string: :: From 34921be5973831e2b322944893a945ec52fbfb09 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 10:37:16 +0900 Subject: [PATCH 05/13] docs: improve sample code --- user_guide_src/source/outgoing/view_cells.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 0c6541984b8e..5d3e28f6ab94 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -58,8 +58,10 @@ You would call it from within a view like: Additionally, you can use parameter names that match the parameter variables in the method for better readability. When you use it this way, all of the parameters must always be specified in the view cell call:: - + // In a View. + + // In a Cell. public function recentPosts(string $category, int $limit) { $posts = $this->blogModel->where('category', $category) From 2e857fd9f833d75b68b6227c9d87dac4c4dcb2e4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:07:45 +0900 Subject: [PATCH 06/13] docs: fix view classname Use the same classname as the above sample code. --- user_guide_src/source/outgoing/view_cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 5d3e28f6ab94..1c6aa25d2697 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -113,7 +113,7 @@ You can also create a controlled cell via a built in command from the CLI. The c :: - > php spark make:cell AlertMessage + > php spark make:cell AlertMessageCell Using a Different View ====================== From 8dc1fdd328819117349eedc321700f21e43da942 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:11:02 +0900 Subject: [PATCH 07/13] docs: escape variables in view Escaping by default is a good practice. --- user_guide_src/source/outgoing/view_cells.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 1c6aa25d2697..587856c100c8 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -100,8 +100,8 @@ At the most basic level, all you need to implement within the class are public p } // app/Cells/alert_message_cell.php -
- +
+
.. _generating-cell-via-command: From eac45b11c5f0d7c2e17c533b2a4de67071fc0eb4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:11:48 +0900 Subject: [PATCH 08/13] docs: add sample code to call the view cell --- user_guide_src/source/outgoing/view_cells.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 587856c100c8..f9dfe846dfdc 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -104,6 +104,9 @@ At the most basic level, all you need to implement within the class are public p
+ // Called in main View: + + .. _generating-cell-via-command: Generating Cell via Command From 1d040700123fcd9c3669ea92adf756d88a0b4c3f Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:20:59 +0900 Subject: [PATCH 09/13] docs: remove unneeded method name --- user_guide_src/source/outgoing/view_cells.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index f9dfe846dfdc..cec751358f32 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -256,7 +256,7 @@ You can pass additional parameters to the ``mount()`` method by passing them as } // Called in main View: - 5]); ?> + 5]); ?> ************ Cell Caching From cf4d29ca4854a6b9673743763716b5af08045eba Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:22:46 +0900 Subject: [PATCH 10/13] docs: remove ; at the end in view sample code --- user_guide_src/source/outgoing/view_cells.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index cec751358f32..048505efb1cd 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -19,19 +19,19 @@ Calling a View Cell No matter which type of View Cell you are using, you can call it from any view by using the ``view_cell()`` helper method. The first parameter is the name of the class and method to call, and the second parameter is an array of parameters to pass to the method. The method must return a string, which will be inserted into the view where the ``view_cell()`` method was called. :: - 'value1', 'param2' => 'value2']); ?> + 'value1', 'param2' => 'value2']) ?> If you do not include the full namespace for the class, it will assume in can be found in the ``App\Cells`` namespace. So, the following example would attempt to find the ``MyClass`` class in ``app/Cells/MyClass.php``. If it is not found there, all namespaces will be scanned until it is found, searching within a ``Cells`` subdirectory of each namespace. :: - 'value1', 'param2' => 'value2']); ?> + 'value1', 'param2' => 'value2']) ?> .. note:: Namespace omission is available since v4.3.0 and later. You can also pass the parameters along as a key/value string: :: - + ************ Simple Cells @@ -53,7 +53,7 @@ Simple Cells are classes that return a string from the chosen method. An example You would call it from within a view like: :: - 'success', 'message' => 'The user has been updated.']); ?> + 'success', 'message' => 'The user has been updated.']) ?> Additionally, you can use parameter names that match the parameter variables in the method for better readability. When you use it this way, all of the parameters must always be specified in the view cell call:: @@ -209,7 +209,7 @@ Sometimes you need to perform additional logic for the view, but you don't want
  • linkPost($post) ?>
  • - +
Performing Setup Logic @@ -256,7 +256,7 @@ You can pass additional parameters to the ``mount()`` method by passing them as } // Called in main View: - 5]); ?> + 5]) ?> ************ Cell Caching From 4cde7123aa7da8f779bba956430c718e46622319 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 11:21:19 +0900 Subject: [PATCH 11/13] docs: update cell namespaces --- user_guide_src/source/outgoing/view_cells.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 048505efb1cd..1eb235a618bc 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -267,10 +267,10 @@ third parameter. This will use the currently configured cache engine. :: // Cache the view for 5 minutes - + You can provide a custom name to use instead of the auto-generated one if you like, by passing the new name as the fourth parameter:: // Cache the view for 5 minutes - + From d072835c84d9a0d22559991aa514442747593d78 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 17:07:59 +0900 Subject: [PATCH 12/13] docs: change to AlertMessageCell For consistency. --- user_guide_src/source/outgoing/view_cells.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 1eb235a618bc..ea252c0b6f7a 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -129,7 +129,7 @@ You can specify a custom view name by setting the ``view`` property in the class use CodeIgniter\View\Cells\Cell; - class AlertMessage extends Cell + class AlertMessageCell extends Cell { public $type; public $message; @@ -147,7 +147,7 @@ If you need more control over the rendering of the HTML, you can implement a ``r use CodeIgniter\View\Cells\Cell; - class AlertMessage extends Cell + class AlertMessageCell extends Cell { public $type; public $message; @@ -168,7 +168,7 @@ If you need to perform additional logic for one or more properties you can use c use CodeIgniter\View\Cells\Cell; - class AlertMessage extends Cell + class AlertMessageCell extends Cell { protected $type; protected $message; From 99451b89218a5d16d322a2c42a150c4b7c270300 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Apr 2023 17:14:56 +0900 Subject: [PATCH 13/13] docs: fix cell file names For consistency. --- user_guide_src/source/outgoing/view_cells.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index ea252c0b6f7a..8d60d478c82c 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -195,7 +195,7 @@ Sometimes you need to perform additional logic for the view, but you don't want use CodeIgniter\View\Cells\Cell; - class RecentPosts extends Cell + class RecentPostsCell extends Cell { protected $posts; @@ -205,7 +205,7 @@ Sometimes you need to perform additional logic for the view, but you don't want } } - // app/Cells/recent_posts.php + // app/Cells/recent_posts_cell.php
  • linkPost($post) ?>
  • @@ -223,7 +223,7 @@ If you need to perform additional logic before the view is rendered, you can imp use CodeIgniter\View\Cells\Cell; - class RecentPosts extends Cell + class RecentPostsCell extends Cell { protected $posts; @@ -236,12 +236,12 @@ If you need to perform additional logic before the view is rendered, you can imp You can pass additional parameters to the ``mount()`` method by passing them as an array to the ``view_cell()`` helper function. Any of the parameters sent that match a parameter name of the ``mount`` method will be passed in. :: - // app/Cells/RecentPosts.php + // app/Cells/RecentPostsCell.php namespace App\Cells; use CodeIgniter\View\Cells\Cell; - class RecentPosts extends Cell + class RecentPostsCell extends Cell { protected $posts; @@ -256,7 +256,7 @@ You can pass additional parameters to the ``mount()`` method by passing them as } // Called in main View: - 5]) ?> + 5]) ?> ************ Cell Caching