You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/outgoing/view_cells.rst
+24-8Lines changed: 24 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,20 @@ View Cells
4
4
5
5
Many applications have small view fragments that can be repeated from page to page, or in different places on the pages. These are often help boxes, navigation controls, ads, login forms, etc. CodeIgniter lets you encapsulate the logic for these presentation blocks within View Cells. They are basically mini-views that can be included in other views. They can have logic built in to handle any cell-specific display logic. They can be used to make your views more readable and maintainable by separating the logic for each cell into its own class.
6
6
7
-
CodeIgniter supports two types of View Cells: simple and controlled. Simple View Cells can be generated from any class and method of your choice and does not have to follow any rules, except that it must return a string. Controlled View Cells must be generated from a class that extends ``Codeigniter\View\Cells\Cell`` class which provides additional capability making your View Cells more flexible and faster to use.
8
-
9
7
.. contents::
10
8
:local:
11
9
:depth: 2
12
10
11
+
***************************
12
+
Simple and Controlled Cells
13
+
***************************
14
+
15
+
CodeIgniter supports two types of View Cells: simple and controlled.
16
+
17
+
**Simple View Cells** can be generated from any class and method of your choice and does not have to follow any rules, except that it must return a string.
18
+
19
+
**Controlled View Cells** must be generated from a class that extends ``Codeigniter\View\Cells\Cell`` class which provides additional capability making your View Cells more flexible and faster to use.
20
+
13
21
.. _app-cells:
14
22
15
23
*******************
@@ -18,11 +26,13 @@ Calling a View Cell
18
26
19
27
No matter which type of View Cell you are using, you can call it from any view by using the ``view_cell()`` helper function.
20
28
21
-
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:
29
+
The first parameter is (1) *the name of the class and method* (Simple Cell) or (2) *the name of the class and optional method* (Controlled Cell) to call,
30
+
and the second parameter is an array or string of parameters to pass to the method:
22
31
23
32
.. literalinclude:: view_cells/001.php
24
33
25
-
The Cell method must return a string, which will be inserted into the view where the ``view_cell()`` function was called.
34
+
The string that the Cell returns will be inserted into the view where the
35
+
``view_cell()`` function was called.
26
36
27
37
Namespace Omission
28
38
==================
@@ -67,8 +77,10 @@ Controlled Cells
67
77
68
78
.. versionadded:: 4.3.0
69
79
70
-
Controlled cells have two primary goals: to make it as fast as possible to build the cell, and provide additional logic and
71
-
flexibility to your views, if they need it. The class must extend ``CodeIgniter\View\Cells\Cell``. They should have a view file
80
+
Controlled cells have two primary goals: (1) to make it as fast as possible to build the cell, and (2) provide additional logic and
81
+
flexibility to your views, if they need it.
82
+
83
+
The class must extend ``CodeIgniter\View\Cells\Cell``. They should have a view file
72
84
in the same folder. By convention, the class name should be in PascalCase suffixed with ``Cell`` and the view should be
73
85
the snake_cased version of the class name, without the suffix. For example, if you have a ``MyCell`` class, the view file
74
86
should be ``my.php``.
@@ -79,7 +91,9 @@ should be ``my.php``.
79
91
Creating a Controlled Cell
80
92
==========================
81
93
82
-
At the most basic level, all you need to implement within the class are public properties. These properties will be made available to the view file automatically. Implementing the AlertMessage from above as a Controlled Cell would look like this:
94
+
At the most basic level, all you need to implement within the class are public properties. These properties will be made available to the view file automatically.
95
+
96
+
Implementing the AlertMessage from above as a Controlled Cell would look like this:
83
97
84
98
.. literalinclude:: view_cells/008.php
85
99
@@ -108,7 +122,9 @@ You can specify a custom view name by setting the ``view`` property in the class
108
122
Customize the Rendering
109
123
=======================
110
124
111
-
If you need more control over the rendering of the HTML, you can implement a ``render()`` method. This method allows you to perform additional logic and pass extra data the view, if needed. The ``render()`` method must return a string. To take advantage of the full features of controlled Cells, you should use ``$this->view()`` instead of the normal ``view()`` helper function:
125
+
If you need more control over the rendering of the HTML, you can implement a ``render()`` method. This method allows you to perform additional logic and pass extra data the view, if needed. The ``render()`` method must return a string.
126
+
127
+
To take advantage of the full features of controlled Cells, you should use ``$this->view()`` instead of the normal ``view()`` helper function:
0 commit comments