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
+31-24Lines changed: 31 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,17 +19,19 @@ Calling a View Cell
19
19
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.
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.
24
+
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.
@@ -74,6 +78,8 @@ When you use it this way, all of the parameters must always be specified in the
74
78
Controlled Cells
75
79
****************
76
80
81
+
.. versionadded:: 4.3.0
82
+
77
83
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``.
78
84
79
85
Creating a Controlled Cell
@@ -94,22 +100,23 @@ At the most basic level, all you need to implement within the class are public p
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.
109
116
110
117
::
111
118
112
-
> php spark make:cell AlertMessage
119
+
> php spark make:cell AlertMessageCell
113
120
114
121
Using a Different View
115
122
======================
@@ -122,7 +129,7 @@ You can specify a custom view name by setting the ``view`` property in the class
122
129
123
130
use CodeIgniter\View\Cells\Cell;
124
131
125
-
class AlertMessage extends Cell
132
+
class AlertMessageCell extends Cell
126
133
{
127
134
public $type;
128
135
public $message;
@@ -140,7 +147,7 @@ If you need more control over the rendering of the HTML, you can implement a ``r
140
147
141
148
use CodeIgniter\View\Cells\Cell;
142
149
143
-
class AlertMessage extends Cell
150
+
class AlertMessageCell extends Cell
144
151
{
145
152
public $type;
146
153
public $message;
@@ -161,7 +168,7 @@ If you need to perform additional logic for one or more properties you can use c
161
168
162
169
use CodeIgniter\View\Cells\Cell;
163
170
164
-
class AlertMessage extends Cell
171
+
class AlertMessageCell extends Cell
165
172
{
166
173
protected $type;
167
174
protected $message;
@@ -188,7 +195,7 @@ Sometimes you need to perform additional logic for the view, but you don't want
188
195
189
196
use CodeIgniter\View\Cells\Cell;
190
197
191
-
class RecentPosts extends Cell
198
+
class RecentPostsCell extends Cell
192
199
{
193
200
protected $posts;
194
201
@@ -198,11 +205,11 @@ Sometimes you need to perform additional logic for the view, but you don't want
198
205
}
199
206
}
200
207
201
-
// app/Cells/recent_posts.php
208
+
// app/Cells/recent_posts_cell.php
202
209
<ul>
203
210
<?php foreach ($posts as $post): ?>
204
211
<li><?= $this->linkPost($post) ?></li>
205
-
<?php endforeach; ?>
212
+
<?php endforeach ?>
206
213
</ul>
207
214
208
215
Performing Setup Logic
@@ -216,7 +223,7 @@ If you need to perform additional logic before the view is rendered, you can imp
216
223
217
224
use CodeIgniter\View\Cells\Cell;
218
225
219
-
class RecentPosts extends Cell
226
+
class RecentPostsCell extends Cell
220
227
{
221
228
protected $posts;
222
229
@@ -229,12 +236,12 @@ If you need to perform additional logic before the view is rendered, you can imp
229
236
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.
230
237
::
231
238
232
-
// app/Cells/RecentPosts.php
239
+
// app/Cells/RecentPostsCell.php
233
240
namespace App\Cells;
234
241
235
242
use CodeIgniter\View\Cells\Cell;
236
243
237
-
class RecentPosts extends Cell
244
+
class RecentPostsCell extends Cell
238
245
{
239
246
protected $posts;
240
247
@@ -249,7 +256,7 @@ You can pass additional parameters to the ``mount()`` method by passing them as
0 commit comments