Skip to content

Commit

Permalink
Update cell documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed May 11, 2023
1 parent 82f33d4 commit f5ade58
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 9 additions & 0 deletions user_guide_src/source/changelogs/v4.3.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ Message Changes
Changes
*******

- **make:cell** When creating a new cell, the controller would always have the ``Cell`` suffixed to the class name.
For the view file, the final ``_cell`` is always removed.
- **Cells** For compatibility with previous versions, view filenames ending with ``_cell`` can still be
located by the ``Cell`` as long as auto-detection of view file is enabled (via setting the ``$view`` property
to an empty string).

Deprecations
************

Bugs Fixed
**********

- **make:cell** Fixed generating view files as classes.
- **make:cell** Fixed treatment of single word class input for case-insensitive OS.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.
3 changes: 1 addition & 2 deletions user_guide_src/source/cli/cli_generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ Usage:

Argument:
=========
* ``name``: The name of the cell class. It should be in PascalCase.
* ``name``: The name of the cell class. It should be in PascalCase. **[REQUIRED]**

Options:
========
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
* ``--suffix``: Append the component suffix to the generated class name.
* ``--force``: Set this flag to overwrite existing files on destination.

make:command
Expand Down
16 changes: 12 additions & 4 deletions user_guide_src/source/outgoing/view_cells.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ Controlled Cells

.. versionadded:: 4.3.0

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``.
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 in PascalCase suffixed with ``Cell`` and the view should be
the snake_cased version of the class name, without the suffix. For example, if you have a ``MyCell`` class, the view file
should be ``my.php``.

.. note:: Prior to v4.3.5, the generated view file ends with ``_cell.php``. This was deemed incorrect and corrected accordingly.
For backward compatibility, existing view files ending with ``_cell.php`` will still be located and loaded. However, it is
recommended to update the filenames to remove the trailing ``_cell``.

Creating a Controlled Cell
==========================
Expand All @@ -99,7 +107,7 @@ At the most basic level, all you need to implement within the class are public p
public $message;
}

// app/Cells/alert_message_cell.php
// app/Cells/alert_message.php
<div class="alert alert-<?= esc($type, 'attr') ?>">
<?= esc($message) ?>
</div>
Expand Down Expand Up @@ -199,7 +207,7 @@ If you need to perform additional logic for one or more properties you can use c
}
}

// app/Cells/alert_message_cell.php
// app/Cells/alert_message.php
<div>
<p>type - <?= esc($type) ?></p>
<p>message - <?= esc($message) ?></p>
Expand Down Expand Up @@ -230,7 +238,7 @@ Sometimes you need to perform additional logic for the view, but you don't want
}
}

// app/Cells/recent_posts_cell.php
// app/Cells/recent_posts.php
<ul>
<?php foreach ($posts as $post): ?>
<li><?= $this->linkPost($post) ?></li>
Expand Down

0 comments on commit f5ade58

Please sign in to comment.