Skip to content

Commit d425bdf

Browse files
authored
Merge pull request #8780 from kenjis/docs-improve-views
docs: improve View pages
2 parents 6a65664 + 9483b35 commit d425bdf

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

user_guide_src/source/general/common_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Service Accessors
180180
:rtype: string
181181

182182
Grabs the current RendererInterface-compatible class
183+
(:doc:`View <../outgoing/view_renderer>` class by default)
183184
and tells it to render the specified view. Simply provides
184185
a convenience method that can be used in Controllers,
185186
libraries, and routed closures.

user_guide_src/source/outgoing/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ View components are used to build what is returned to the user.
88
:titlesonly:
99

1010
views
11-
view_cells
1211
view_renderer
1312
view_layouts
13+
view_cells
1414
view_parser
1515
view_decorators
1616
table

user_guide_src/source/outgoing/view_decorators.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,36 @@
22
View Decorators
33
###############
44

5+
.. contents::
6+
:local:
7+
:depth: 2
8+
9+
*************************
10+
What are View Decorators?
11+
*************************
12+
513
View Decorators allow your application to modify the HTML output during the rendering process. This happens just
614
prior to being cached, and allows you to apply custom functionality to your views.
715

16+
You can use View Decorators with :doc:`view_renderer` or :doc:`view_parser`.
17+
818
*******************
919
Creating Decorators
1020
*******************
1121

22+
Creating Decorator Class
23+
========================
24+
1225
Creating your own view decorators requires creating a new class that implements ``CodeIgniter\View\ViewDecoratorInterface``.
1326
This requires a single method that takes the generated HTML string, performs any modifications on it, and returns
1427
the resulting HTML.
1528

1629
.. literalinclude:: view_decorators/001.php
1730

18-
Once created, the class must be registered in ``app/Config/View.php``:
31+
Registering Decorator Class
32+
===========================
33+
34+
Once created, the class must be registered in **app/Config/View.php**:
1935

2036
.. literalinclude:: view_decorators/002.php
2137

user_guide_src/source/outgoing/view_decorators/002.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
class View extends BaseView
88
{
9+
// ...
10+
911
public array $decorators = [
1012
'App\Views\Decorators\MyDecorator',
1113
];
12-
13-
// ...
1414
}

user_guide_src/source/outgoing/view_parser.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ need to be unique, or a later parameter setting will over-ride an earlier one.
8181
This also impacts escaping parameter values for different contexts inside your
8282
script. You will have to give each escaped value a unique parameter name.
8383

84-
Parser templates
84+
Parser Templates
8585
================
8686

8787
You can use the ``render()`` method to parse (or render) simple templates,
@@ -90,10 +90,12 @@ like this:
9090
.. literalinclude:: view_parser/003.php
9191

9292
View parameters are passed to ``setData()`` as an associative
93-
array of data to be replaced in the template. In the above example, the
94-
template would contain two variables: ``{blog_title}`` and ``{blog_heading}``
95-
The first parameter to ``render()`` contains the name of the :doc:`view
96-
file </outgoing/views>`, Where *blog_template* is the name of your view file.
93+
array of data to be replaced in the template.
94+
95+
In the above example, the template would contain two variables: ``{blog_title}`` and ``{blog_heading}``
96+
97+
The first parameter to ``render()`` contains the name of the template, where
98+
``blog_template`` is the name of your view template file.
9799

98100
.. important:: If the file extension is omitted, then the views are expected to end with the .php extension.
99101

@@ -102,7 +104,7 @@ Parser Configuration Options
102104

103105
Several options can be passed to the ``render()`` or ``renderString()`` methods.
104106

105-
- ``cache`` - the time in seconds, to save a view's results; ignored for renderString()
107+
- ``cache`` - the time in seconds, to save a view's results; ignored for ``renderString()``
106108
- ``cache_name`` - the ID used to save/retrieve a cached view result; defaults to the viewpath;
107109
ignored for renderString()
108110
- ``saveData`` - true if the view data parameters should be retained for subsequent calls;

user_guide_src/source/outgoing/views.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Where *name* is the name of your view file.
4747

4848
.. important:: If the file extension is omitted, then the views are expected to end with the **.php** extension.
4949

50+
.. note:: The ``view()`` function uses :doc:`view_renderer` internally.
51+
5052
Now, create a file called **Blog.php** in the **app/Controllers** directory,
5153
and put this in it:
5254

0 commit comments

Comments
 (0)