From 799b5056d17875d385451d6bf3ed2a0dcd2c986a Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:11:02 +0900 Subject: [PATCH 1/7] docs: add note on view() and View Renderer relationship --- user_guide_src/source/general/common_functions.rst | 1 + user_guide_src/source/outgoing/views.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index b16b5576ee45..05e43026675d 100755 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -180,6 +180,7 @@ Service Accessors :rtype: string Grabs the current RendererInterface-compatible class + (:doc:`View <../outgoing/view_renderer>` class by default) and tells it to render the specified view. Simply provides a convenience method that can be used in Controllers, libraries, and routed closures. diff --git a/user_guide_src/source/outgoing/views.rst b/user_guide_src/source/outgoing/views.rst index fabd811de87a..611631ea6d5a 100644 --- a/user_guide_src/source/outgoing/views.rst +++ b/user_guide_src/source/outgoing/views.rst @@ -47,6 +47,8 @@ Where *name* is the name of your view file. .. important:: If the file extension is omitted, then the views are expected to end with the **.php** extension. +.. note:: The ``view()`` function uses :doc:`view_renderer` internally. + Now, create a file called **Blog.php** in the **app/Controllers** directory, and put this in it: From a25275ab175a5c26c34132f3d6c89cd4c1d1466c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:16:21 +0900 Subject: [PATCH 2/7] docs: change page order "Views" page is an explanation of the standard views. The standard views use View Renderer. So the two pages should be close. --- user_guide_src/source/outgoing/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/index.rst b/user_guide_src/source/outgoing/index.rst index a08a2e52a125..7b643ae5aad7 100644 --- a/user_guide_src/source/outgoing/index.rst +++ b/user_guide_src/source/outgoing/index.rst @@ -8,9 +8,9 @@ View components are used to build what is returned to the user. :titlesonly: views - view_cells view_renderer view_layouts + view_cells view_parser view_decorators table From 2091c4265f0b725b9e53db25307e04baa349dee8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:29:07 +0900 Subject: [PATCH 3/7] docs: capitalize first letter --- user_guide_src/source/outgoing/view_parser.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_parser.rst b/user_guide_src/source/outgoing/view_parser.rst index 6b82129c64c9..d06161c2840f 100644 --- a/user_guide_src/source/outgoing/view_parser.rst +++ b/user_guide_src/source/outgoing/view_parser.rst @@ -81,7 +81,7 @@ need to be unique, or a later parameter setting will over-ride an earlier one. This also impacts escaping parameter values for different contexts inside your script. You will have to give each escaped value a unique parameter name. -Parser templates +Parser Templates ================ You can use the ``render()`` method to parse (or render) simple templates, From 312778454869cc88790446ba09d25a836c8bf407 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:29:46 +0900 Subject: [PATCH 4/7] docs: decorate method name --- user_guide_src/source/outgoing/view_parser.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_parser.rst b/user_guide_src/source/outgoing/view_parser.rst index d06161c2840f..4202f478e1fe 100644 --- a/user_guide_src/source/outgoing/view_parser.rst +++ b/user_guide_src/source/outgoing/view_parser.rst @@ -102,7 +102,7 @@ Parser Configuration Options Several options can be passed to the ``render()`` or ``renderString()`` methods. -- ``cache`` - the time in seconds, to save a view's results; ignored for renderString() +- ``cache`` - the time in seconds, to save a view's results; ignored for ``renderString()`` - ``cache_name`` - the ID used to save/retrieve a cached view result; defaults to the viewpath; ignored for renderString() - ``saveData`` - true if the view data parameters should be retained for subsequent calls; From 7b45a2b5281c89f365da270f95044ebcc989056d Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:30:16 +0900 Subject: [PATCH 5/7] docs: improve description The views in "Views" page is pure PHP views. It is different from Parser Template views. So I removed the link to "Views" page. --- user_guide_src/source/outgoing/view_parser.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/outgoing/view_parser.rst b/user_guide_src/source/outgoing/view_parser.rst index 4202f478e1fe..dab40c9b9750 100644 --- a/user_guide_src/source/outgoing/view_parser.rst +++ b/user_guide_src/source/outgoing/view_parser.rst @@ -90,10 +90,12 @@ like this: .. literalinclude:: view_parser/003.php View parameters are passed to ``setData()`` as an associative -array of data to be replaced in the template. In the above example, the -template would contain two variables: ``{blog_title}`` and ``{blog_heading}`` -The first parameter to ``render()`` contains the name of the :doc:`view -file `, Where *blog_template* is the name of your view file. +array of data to be replaced in the template. + +In the above example, the template would contain two variables: ``{blog_title}`` and ``{blog_heading}`` + +The first parameter to ``render()`` contains the name of the template, where +``blog_template``` is the name of your view template file. .. important:: If the file extension is omitted, then the views are expected to end with the .php extension. From 4d88c19c30bb09befb59abd9f28280dac34897ff Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 09:42:12 +0900 Subject: [PATCH 6/7] docs: add section titles and descriptions --- .../source/outgoing/view_decorators.rst | 18 +++++++++++++++++- .../source/outgoing/view_decorators/002.php | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/outgoing/view_decorators.rst b/user_guide_src/source/outgoing/view_decorators.rst index f0b2239b0f65..29c8c25c7418 100644 --- a/user_guide_src/source/outgoing/view_decorators.rst +++ b/user_guide_src/source/outgoing/view_decorators.rst @@ -2,20 +2,36 @@ View Decorators ############### +.. contents:: + :local: + :depth: 2 + +************************* +What are View Decorators? +************************* + View Decorators allow your application to modify the HTML output during the rendering process. This happens just prior to being cached, and allows you to apply custom functionality to your views. +You can use View Decorators with :doc:`view_renderer` or :doc:`view_parser`. + ******************* Creating Decorators ******************* +Creating Decorator Class +======================== + Creating your own view decorators requires creating a new class that implements ``CodeIgniter\View\ViewDecoratorInterface``. This requires a single method that takes the generated HTML string, performs any modifications on it, and returns the resulting HTML. .. literalinclude:: view_decorators/001.php -Once created, the class must be registered in ``app/Config/View.php``: +Registering Decorator Class +=========================== + +Once created, the class must be registered in **app/Config/View.php**: .. literalinclude:: view_decorators/002.php diff --git a/user_guide_src/source/outgoing/view_decorators/002.php b/user_guide_src/source/outgoing/view_decorators/002.php index ba56ea1e80ad..b0634187b51d 100644 --- a/user_guide_src/source/outgoing/view_decorators/002.php +++ b/user_guide_src/source/outgoing/view_decorators/002.php @@ -6,9 +6,9 @@ class View extends BaseView { + // ... + public array $decorators = [ 'App\Views\Decorators\MyDecorator', ]; - - // ... } From 9483b354431be24b6a9a82d1d31e98eb47d1fc9e Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 14 Apr 2024 10:08:04 +0900 Subject: [PATCH 7/7] docs: fix typo Co-authored-by: Pooya Parsa --- user_guide_src/source/outgoing/view_parser.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/outgoing/view_parser.rst b/user_guide_src/source/outgoing/view_parser.rst index dab40c9b9750..a439d907a1de 100644 --- a/user_guide_src/source/outgoing/view_parser.rst +++ b/user_guide_src/source/outgoing/view_parser.rst @@ -95,7 +95,7 @@ array of data to be replaced in the template. In the above example, the template would contain two variables: ``{blog_title}`` and ``{blog_heading}`` The first parameter to ``render()`` contains the name of the template, where -``blog_template``` is the name of your view template file. +``blog_template`` is the name of your view template file. .. important:: If the file extension is omitted, then the views are expected to end with the .php extension.