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/incoming/controllers.rst
+14-6Lines changed: 14 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,12 +278,17 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
278
278
Auto Routing (Improved) does not execute the method, and it results in 404
279
279
Not Found.
280
280
281
+
Default Controller
282
+
==================
283
+
284
+
The Default Controller is a special controller that is used when a URI end with
285
+
a directory name or when a URI is not present, as will be the case when only your
286
+
site root URL is requested.
287
+
281
288
Defining a Default Controller
282
-
=============================
289
+
-----------------------------
283
290
284
-
CodeIgniter can be told to load a default controller when a URI is not
285
-
present, as will be the case when only your site root URL is requested. Let's try it
286
-
with the ``Helloworld`` controller.
291
+
Let's try it with the ``Helloworld`` controller.
287
292
288
293
To specify a default controller open your **app/Config/Routes.php**
289
294
file and set this variable:
@@ -299,10 +304,13 @@ A few lines further down **Routes.php** in the "Route Definitions" section, comm
299
304
If you now browse to your site without specifying any URI segments you'll
300
305
see the "Hello World" message.
301
306
302
-
.. note:: The line ``$routes->get('/', 'Home::index');`` is an optimization that you will want to use in a "real-world" app. But for demonstration purposes we don't want to use that feature. ``$routes->get()`` is explained in :doc:`URI Routing <routing>`
307
+
.. important:: When you use Auto Routing (Improved), you must remove the line
308
+
``$routes->get('/', 'Home::index');``. Because defined routes take
309
+
precedence over Auto Routing, and controllers defined in the defined routes
310
+
are denied access by Auto Routing (Improved) for security reasons.
303
311
304
312
For more information, please refer to the :ref:`routes-configuration-options` section of the
0 commit comments