diff --git a/system/Commands/Generators/CellGenerator.php b/system/Commands/Generators/CellGenerator.php index cf4757d10eeb..358bacc0c434 100644 --- a/system/Commands/Generators/CellGenerator.php +++ b/system/Commands/Generators/CellGenerator.php @@ -40,7 +40,7 @@ class CellGenerator extends BaseCommand * * @var string */ - protected $description = 'Generates a new Cell file and its view.'; + protected $description = 'Generates a new Controlled Cell file and its view.'; /** * The Command's Usage @@ -55,7 +55,7 @@ class CellGenerator extends BaseCommand * @var array */ protected $arguments = [ - 'name' => 'The cell class name.', + 'name' => 'The Controlled Cell class name.', ]; /** diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index 6e62340c6ded..aadf72ee19ad 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -23,7 +23,7 @@
diff --git a/system/HotReloader/HotReloader.php b/system/HotReloader/HotReloader.php index 564ba544283a..579bcd4ac598 100644 --- a/system/HotReloader/HotReloader.php +++ b/system/HotReloader/HotReloader.php @@ -18,6 +18,10 @@ final class HotReloader { public function run(): void { + if (session_status() === PHP_SESSION_ACTIVE) { + session_write_close(); + } + ini_set('zlib.output_compression', 'Off'); header('Cache-Control: no-store'); diff --git a/user_guide_src/source/incoming/filters.rst b/user_guide_src/source/incoming/filters.rst index 5292841d895f..2ed3e9eeeddb 100644 --- a/user_guide_src/source/incoming/filters.rst +++ b/user_guide_src/source/incoming/filters.rst @@ -119,9 +119,12 @@ You should define as many aliases as you need. $globals -------- -The second section allows you to define any filters that should be applied to every request made by the framework. +The second section allows you to define any filters that should be applied to every valid request made by the framework. + You should take care with how many you use here, since it could have performance implications to have too many -run on every request. Filters can be specified by adding their alias to either the before or after array: +run on every request. + +Filters can be specified by adding their alias to either the ``before`` or ``after`` array: .. literalinclude:: filters/005.php @@ -130,14 +133,18 @@ Except for a Few URIs There are times where you want to apply a filter to almost every request, but have a few that should be left alone. One common example is if you need to exclude a few URI's from the CSRF protection filter to allow requests from -third-party websites to hit one or two specific URI's, while keeping the rest of them protected. To do this, add +third-party websites to hit one or two specific URI's, while keeping the rest of them protected. + +To do this, add an array with the ``except`` key and a URI path (relative to BaseURL) to match as the value alongside the alias: .. literalinclude:: filters/006.php Any place you can use a URI path (relative to BaseURL) in the filter settings, you can use a regular expression or, like in this example, use an asterisk (``*``) for a wildcard that will match all characters after that. In this example, any URI path starting with ``api/`` -would be exempted from CSRF protection, but the site's forms would all be protected. If you need to specify multiple +would be exempted from CSRF protection, but the site's forms would all be protected. + +If you need to specify multiple URI paths, you can use an array of URI path patterns: .. literalinclude:: filters/007.php diff --git a/user_guide_src/source/incoming/filters/004.php b/user_guide_src/source/incoming/filters/004.php index 304bd21b53eb..fbaa8358ad60 100644 --- a/user_guide_src/source/incoming/filters/004.php +++ b/user_guide_src/source/incoming/filters/004.php @@ -7,7 +7,7 @@ class Filters extends BaseConfig { public array $aliases = [ - 'apiPrep' => [ + 'api-prep' => [ \App\Filters\Negotiate::class, \App\Filters\ApiAuth::class, ], diff --git a/user_guide_src/source/incoming/filters/008.php b/user_guide_src/source/incoming/filters/008.php index 945e9498b4f9..8d417fd436aa 100644 --- a/user_guide_src/source/incoming/filters/008.php +++ b/user_guide_src/source/incoming/filters/008.php @@ -9,7 +9,7 @@ class Filters extends BaseConfig // ... public array $methods = [ - 'post' => ['InvalidChars', 'csrf'], + 'post' => ['invalidchars', 'csrf'], 'get' => ['csrf'], ]; diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index 09b62bcad16a..f940bc99ea17 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -4,12 +4,20 @@ View Cells 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. -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. - .. contents:: :local: :depth: 2 +*************************** +Simple and Controlled Cells +*************************** + +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. + .. _app-cells: ******************* @@ -18,11 +26,13 @@ Calling a View Cell No matter which type of View Cell you are using, you can call it from any view by using the ``view_cell()`` helper function. -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 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, +and the second parameter is an array or string of parameters to pass to the method: .. literalinclude:: view_cells/001.php -The Cell method must return a string, which will be inserted into the view where the ``view_cell()`` function was called. +The string that the Cell returns will be inserted into the view where the +``view_cell()`` function was called. Namespace Omission ================== @@ -67,8 +77,10 @@ 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 +Controlled cells have two primary goals: (1) to make it as fast as possible to build the cell, and (2) 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``. @@ -79,7 +91,9 @@ should be ``my.php``. Creating a Controlled Cell ========================== -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: +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: .. literalinclude:: view_cells/008.php @@ -108,7 +122,9 @@ You can specify a custom view name by setting the ``view`` property in the class Customize the Rendering ======================= -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: +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: .. literalinclude:: view_cells/012.php diff --git a/user_guide_src/source/outgoing/view_cells/001.php b/user_guide_src/source/outgoing/view_cells/001.php index 2a9e4361796e..57a4fdc425dc 100644 --- a/user_guide_src/source/outgoing/view_cells/001.php +++ b/user_guide_src/source/outgoing/view_cells/001.php @@ -1,2 +1,7 @@ // In a View. + +// Simple Cell 'value1', 'param2' => 'value2']) ?> + +// Controlled Cell + 'value1', 'param2' => 'value2']) ?> diff --git a/user_guide_src/source/outgoing/view_cells/014.php b/user_guide_src/source/outgoing/view_cells/014.php index 29378e1199ab..7aa1ad4c9d8c 100644 --- a/user_guide_src/source/outgoing/view_cells/014.php +++ b/user_guide_src/source/outgoing/view_cells/014.php @@ -12,7 +12,7 @@ class AlertMessageCell extends Cell protected $message; private $computed; - public function mount() + public function mount(): void { $this->computed = sprintf('%s - %s', $this->type, $this->message); } diff --git a/user_guide_src/source/outgoing/view_cells/016.php b/user_guide_src/source/outgoing/view_cells/016.php index 4b2c10ef0cc6..54d9d7d994a4 100644 --- a/user_guide_src/source/outgoing/view_cells/016.php +++ b/user_guide_src/source/outgoing/view_cells/016.php @@ -10,7 +10,7 @@ class RecentPostsCell extends Cell { protected $posts; - public function linkPost($post) + public function linkPost($post): string { return anchor('posts/' . $post->id, $post->title); } diff --git a/user_guide_src/source/outgoing/view_cells/018.php b/user_guide_src/source/outgoing/view_cells/018.php index 3f64e68464e9..8767af1b40a2 100644 --- a/user_guide_src/source/outgoing/view_cells/018.php +++ b/user_guide_src/source/outgoing/view_cells/018.php @@ -8,7 +8,7 @@ class RecentPostsCell extends Cell { protected $posts; - public function mount() + public function mount(): void { $this->posts = model('PostModel')->orderBy('created_at', 'DESC')->findAll(10); } diff --git a/user_guide_src/source/outgoing/view_cells/019.php b/user_guide_src/source/outgoing/view_cells/019.php index df78ab0acec5..db1b12b56b54 100644 --- a/user_guide_src/source/outgoing/view_cells/019.php +++ b/user_guide_src/source/outgoing/view_cells/019.php @@ -10,7 +10,7 @@ class RecentPostsCell extends Cell { protected $posts; - public function mount(?int $categoryId) + public function mount(?int $categoryId): void { $this->posts = model('PostModel') ->when(