Skip to content

Commit f95f997

Browse files
committed
docs: update description for 404 Override
1 parent 65c6692 commit f95f997

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

user_guide_src/source/incoming/routing.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,19 @@ to only those defined by you, by setting the ``$autoRoute`` property to false:
667667
404 Override
668668
============
669669

670-
When a page is not found that matches the current URI, the system will show a generic 404 view. You can change
671-
what happens by specifying an action to happen with the ``set404Override()`` method. The value can be either
672-
a valid class/method pair, just like you would show in any route, or a Closure:
670+
When a page is not found that matches the current URI, the system will show a
671+
generic 404 view. Using the ``$override404`` property within the routing config
672+
file, you can define controller class/method for 404 routes.
673673

674674
.. literalinclude:: routing/051.php
675675

676-
Using the ``$override404`` property within the routing config file, you can use closures. Defining the override in the Routing file is restricted to class/method pairs.
676+
You can also change what happens by specifying an action to happen with the
677+
``set404Override()`` method in Routes config file. The value can be either a
678+
valid class/method pair, or a Closure:
677679

678-
.. note:: The ``set404Override()`` method does not change the Response status code to ``404``.
680+
.. literalinclude:: routing/069.php
681+
682+
.. note:: The 404 Override feature does not change the Response status code to ``404``.
679683
If you don't set the status code in the controller you set, the default status code ``200``
680684
will be returned. See :php:meth:`CodeIgniter\\HTTP\\Response::setStatusCode()` for
681685
information on how to set the status code.

user_guide_src/source/incoming/routing/051.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,3 @@ class Routing extends BaseRouting
1010
public ?string $override404 = 'App\Errors::show404';
1111
// ...
1212
}
13-
14-
// In app/Config/Routes.php
15-
// Would execute the show404 method of the App\Errors class
16-
$routes->set404Override('App\Errors::show404');
17-
18-
// Will display a custom view
19-
$routes->set404Override(static function () {
20-
echo view('my_errors/not_found.html');
21-
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// In app/Config/Routes.php
4+
// Would execute the show404 method of the App\Errors class
5+
$routes->set404Override('App\Errors::show404');
6+
7+
// Will display a custom view
8+
$routes->set404Override(static function () {
9+
echo view('my_errors/not_found.html');
10+
});

0 commit comments

Comments
 (0)