Skip to content

Commit c94e64a

Browse files
authored
Merge pull request #8488 from kenjis/docs-update-404-override
docs: update description for 404 Override
2 parents 65c6692 + 60042fb commit c94e64a

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

app/Config/Routing.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ class Routing extends BaseRouting
6363

6464
/**
6565
* Sets the class/method that should be called if routing doesn't
66-
* find a match. It can be either a closure or the controller/method
67-
* name exactly like a route is defined: Users::index
66+
* find a match. It can be the controller/method name like: Users::index
6867
*
6968
* This setting is passed to the Router class and handled there.
7069
*
7170
* If you want to use a closure, you will have to set it in the
72-
* class constructor or the routes file by calling:
71+
* routes file by calling:
7372
*
7473
* $routes->set404Override(function() {
7574
* // Do something here

system/Config/Routing.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ class Routing extends BaseConfig
6161

6262
/**
6363
* Sets the class/method that should be called if routing doesn't
64-
* find a match. It can be either a closure or the controller/method
65-
* name exactly like a route is defined: Users::index
64+
* find a match. It can be the controller/method name like: Users::index
6665
*
6766
* This setting is passed to the Router class and handled there.
6867
*
6968
* If you want to use a closure, you will have to set it in the
70-
* class constructor or the routes file by calling:
69+
* routes file by calling:
7170
*
7271
* $routes->set404Override(function() {
7372
* // Do something here

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)