Skip to content

Commit 8386bec

Browse files
committed
docs: Explanations for the View
1 parent ab67240 commit 8386bec

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

user_guide_src/source/outgoing/view_cells.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ You can also create a controlled cell via a built in command from the CLI. The c
119119
Using a Different View
120120
======================
121121

122-
You can specify a custom view name by setting the ``view`` property in the class. The view will be located like any view would be normally:
122+
You can specify a custom view filepath by setting the ``view`` property in the class. The view will be located like any view would be normally:
123123

124124
.. literalinclude:: view_cells/011.php
125125

@@ -145,16 +145,20 @@ If you need to perform additional logic for one or more properties you can use c
145145

146146
.. important:: You can't set properties that are declared as private during cell
147147
initialization.
148+
Call ``getDataProperty()``, ``getViewProperty()`` methods are not available - they are used for internal processes.
148149

149150
Presentation Methods
150151
====================
151152

152153
Sometimes you need to perform additional logic for the view, but you don't want to pass it as a parameter. You can implement a method that will be called from within the cell's view itself. This can help the readability of your views:
154+
You may have noticed that not only method calls are allowed in the template: the entire Сell object with public properties is available.
153155

154156
.. literalinclude:: view_cells/016.php
155157

156158
.. literalinclude:: view_cells/017.php
157159

160+
161+
158162
Performing Setup Logic
159163
======================
160164

user_guide_src/source/outgoing/view_cells/011.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class AlertMessageCell extends Cell
99
public $type;
1010
public $message;
1111

12-
protected string $view = 'my/custom/view';
12+
protected string $view = APPPATH . 'Views/cells/alerts.php';
1313
}

user_guide_src/source/outgoing/view_layouts.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The ``extend()`` method takes the name of any view file that you wish to use. Si
6464
be located just like a view. By default, it will look in the application's View directory, but will also scan
6565
other PSR-4 defined namespaces. You can include a namespace to locate the view in particular namespace View directory::
6666

67-
<?= $this->extend('Blog\Views\default') ?>
67+
<?= $this->extend('Blog\default') ?>
6868

6969
All content within a view that extends a layout must be included within ``section($name)`` and ``endSection()`` method calls.
7070
Any content between these calls will be inserted into the layout wherever the ``renderSection($name)`` call that
@@ -122,3 +122,15 @@ view to view. When using view layouts you must use ``$this->include()`` to inclu
122122

123123
When calling the ``include()`` method, you can pass it all of the same options that can when rendering a normal view, including
124124
cache directives, etc.
125+
126+
*********************
127+
Assign Data to Layers
128+
*********************
129+
130+
You can pass additional variables to your templates, just like for ``view()``. If you don't use the ``saveData = false`` flag anywhere
131+
in the templates, then the data will be inherited for each block.
132+
133+
.. note:: When using a loop, passing new variables is required.
134+
135+
.. literalinclude:: view_layouts/002.php
136+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?= $this->setVar('title', 'Homepage')->extend('default') ?>
2+
3+
<?= $this->setVar('hideNavbar', true)->section('content') ?>
4+
<h1>Items List</h1>
5+
<?php foreach ($items as $item): ?>
6+
<?= $this->setData(['item' => $item])->include('item_card') ?>
7+
<?php endforeach ?>
8+
<?= $this->endSection() ?>

user_guide_src/source/outgoing/views.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,16 @@ When doing so you will need to include the directory name loading the view. Exam
9191
Namespaced Views
9292
================
9393

94-
You can store views under a **View** directory that is namespaced, and load that view as if it was namespaced. While
94+
You can store views under a **Views** directory that is namespaced, and load that view as if it was namespaced. While
9595
PHP does not support loading non-class files from a namespace, CodeIgniter provides this feature to make it possible
9696
to package your views together in a module-like fashion for easy re-use or distribution.
9797

9898
If you have **example/blog** directory that has a PSR-4 mapping set up in the :doc:`Autoloader </concepts/autoloader>` living
9999
under the namespace ``Example\Blog``, you could retrieve view files as if they were namespaced also.
100100

101101
Following this
102-
example, you could load the **blog_view.php** file from **example/blog/Views** by prepending the namespace to the view name:
102+
example, you could load the **blog_view.php** file from **example/blog/Views** by prepending the namespace to the view name
103+
(specifying the end directory ``Views`` as an ``Example\Blog\Views\`` not required):
103104

104105
.. literalinclude:: views/005.php
105106

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
return view('Example\Blog\Views\blog_view');
3+
return view('Example\Blog\blog_view');

0 commit comments

Comments
 (0)