You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/general/errors.rst
+26-2Lines changed: 26 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,8 +101,7 @@ This is used to signal a 404, Page Not Found error:
101
101
102
102
You can pass a message into the exception that will be displayed in place of the default message on the 404 page.
103
103
104
-
When thrown, the system will show the view found at
105
-
**app/Views/errors/html/error_404.php**. You should customize all of the error views for your site.
104
+
For the default 404 view file location, see :ref:`http-status-code-and-error-views`.
106
105
107
106
If, in **app/Config/Routing.php** or **app/Config/Routes.php**, you have specified
108
107
a :ref:`404-override`, that will be called instead of the standard 404 page.
@@ -161,6 +160,31 @@ Since v4.3.0, you can specify the HTTP status code for your Exception class to i
161
160
162
161
When an exception implementing ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will become the HTTP status code.
163
162
163
+
.. _http-status-code-and-error-views:
164
+
165
+
HTTP Status Code and Error Views
166
+
================================
167
+
168
+
The exception handler displays the error view corresponding to the HTTP status
169
+
code, if it exists.
170
+
171
+
For example, ``PageNotFoundException`` implements the ``HTTPExceptionInterface``,
172
+
so its exception code ``404`` will be the HTTP status code. Therefore if it is
173
+
thrown, the system will show the **error_404.php** in the **app/Views/errors/html**
174
+
folder when it is a web request. If it is invoked via CLI, the system will show
175
+
the **error_404.php** in the **app/Views/errors/cli** folder.
176
+
177
+
You should customize all of the error views in the **app/Views/error** folder for
178
+
your site.
179
+
180
+
You can also create error views for specific HTTP status code. For example, if
181
+
you want to create an error view for "400 Bad Request", add **error_400.php**.
182
+
183
+
.. warning:: If an error view file with the corresponding HTTP status code exists,
184
+
the exception handler will display that file regardless of the environment.
185
+
The view file must be implemented in such a way that it does not display
186
+
detailed error messages in production environment by yourself.
0 commit comments