Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion user_guide_src/source/outgoing/view_cells.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ You can also create a controlled cell via a built in command from the CLI. The c
Using a Different View
======================

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:
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:

.. literalinclude:: view_cells/011.php

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

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

Presentation Methods
====================

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:
You may have noticed that not only method calls are allowed in the template: the entire Сell object with public properties is available.

.. literalinclude:: view_cells/016.php

.. literalinclude:: view_cells/017.php



Performing Setup Logic
======================

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/outgoing/view_cells/011.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class AlertMessageCell extends Cell
public $type;
public $message;

protected string $view = 'my/custom/view';
protected string $view = APPPATH . 'Views/cells/alerts.php';
}
14 changes: 13 additions & 1 deletion user_guide_src/source/outgoing/view_layouts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The ``extend()`` method takes the name of any view file that you wish to use. Si
be located just like a view. By default, it will look in the application's View directory, but will also scan
other PSR-4 defined namespaces. You can include a namespace to locate the view in particular namespace View directory::

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

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

When calling the ``include()`` method, you can pass it all of the same options that can when rendering a normal view, including
cache directives, etc.

*********************
Assign Data to Layers
*********************

You can pass additional variables to your templates, just like for ``view()``. If you don't use the ``saveData = false`` flag anywhere
in the templates, then the data will be inherited for each block.

.. note:: When using a loop, passing new variables is required.

.. literalinclude:: view_layouts/002.php

8 changes: 8 additions & 0 deletions user_guide_src/source/outgoing/view_layouts/002.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?= $this->setVar('title', 'Homepage')->extend('default') ?>

<?= $this->setVar('hideNavbar', true)->section('content') ?>
<h1>Items List</h1>
<?php foreach ($items as $item): ?>
<?= $this->setData(['item' => $item])->include('item_card') ?>
<?php endforeach ?>
<?= $this->endSection() ?>
5 changes: 3 additions & 2 deletions user_guide_src/source/outgoing/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ When doing so you will need to include the directory name loading the view. Exam
Namespaced Views
================

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

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

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

.. literalinclude:: views/005.php

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/outgoing/views/005.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return view('Example\Blog\Views\blog_view');
return view('Example\Blog\blog_view');