Skip to content

Commit 4ebf0e7

Browse files
committed
docs: improve description for Default Controller in Auto-Routing Legacy
1 parent ebee1aa commit 4ebf0e7

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

user_guide_src/source/incoming/controllers.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,17 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
456456

457457
.. literalinclude:: controllers/014.php
458458

459-
Defining a Default Controller
460-
=============================
459+
Default Controller (Legacy)
460+
===========================
461461

462-
CodeIgniter can be told to load a default controller when a URI is not
463-
present, as will be the case when only your site root URL is requested. Let's try it
464-
with the ``Helloworld`` controller.
462+
The Default Controller is a special controller that is used when a URI end with
463+
a directory name or when a URI is not present, as will be the case when only your
464+
site root URL is requested.
465+
466+
Defining a Default Controller (Legacy)
467+
--------------------------------------
468+
469+
Let's try it with the ``Helloworld`` controller.
465470

466471
To specify a default controller open your **app/Config/Routes.php**
467472
file and set this variable:
@@ -480,7 +485,7 @@ see the "Hello World" message.
480485
.. 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>`
481486

482487
For more information, please refer to the :ref:`routes-configuration-options` section of the
483-
:doc:`URI Routing <routing>` documentation.
488+
:ref:`URI Routing <routing-auto-routing-legacy-configuration-options>` documentation.
484489

485490
Organizing Your Controllers into Sub-directories (Legacy)
486491
=========================================================

user_guide_src/source/incoming/routing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ and executes ``index()`` method with passing ``'1'`` as the first argument.
757757

758758
See :ref:`Auto Routing (Legacy) in Controllers <controller-auto-routing-legacy>` for more info.
759759

760+
.. _routing-auto-routing-legacy-configuration-options:
761+
760762
Configuration Options (Legacy)
761763
==============================
762764

@@ -765,12 +767,18 @@ These options are available at the top of **app/Config/Routes.php**.
765767
Default Controller (Legacy)
766768
---------------------------
767769

770+
For Site Root URI (Legacy)
771+
^^^^^^^^^^^^^^^^^^^^^^^^^^
772+
768773
When a user visits the root of your site (i.e., example.com) the controller to use is determined by the value set by
769774
the ``setDefaultController()`` method, unless a route exists for it explicitly. The default value for this is ``Home``
770775
which matches the controller at **app/Controllers/Home.php**:
771776

772777
.. literalinclude:: routing/047.php
773778

779+
For Directory URI (Legacy)
780+
^^^^^^^^^^^^^^^^^^^^^^^^^^
781+
774782
The default controller is also used when no matching route has been found, and the URI would point to a directory
775783
in the controllers directory. For example, if the user visits **example.com/admin**, if a controller was found at
776784
**app/Controllers/Admin/Home.php**, it would be used.

0 commit comments

Comments
 (0)