@@ -279,6 +279,40 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
279279
280280.. literalinclude :: controllers/022.php
281281
282+ Default Controller
283+ ==================
284+
285+ The Default Controller is a special controller that is used when a URI ends with
286+ a directory name or when a URI is not present, as will be the case when only your
287+ site root URL is requested.
288+
289+ Defining a Default Controller
290+ -----------------------------
291+
292+ Let's try it with the ``Helloworld `` controller.
293+
294+ To specify a default controller open your **app/Config/Routes.php **
295+ file and set this variable:
296+
297+ .. literalinclude :: controllers/015.php
298+
299+ Where ``Helloworld `` is the name of the controller class you want to be used.
300+
301+ A few lines further down **Routes.php ** in the "Route Definitions" section, comment out the line:
302+
303+ .. literalinclude :: controllers/016.php
304+
305+ If you now browse to your site without specifying any URI segments you'll
306+ see the "Hello World" message.
307+
308+ .. important :: When you use Auto Routing (Improved), you must remove the line
309+ ``$routes->get('/', 'Home::index'); ``. Because defined routes take
310+ precedence over Auto Routing, and controllers defined in the defined routes
311+ are denied access by Auto Routing (Improved) for security reasons.
312+
313+ For more information, please refer to the :ref: `routes-configuration-options ` section of the
314+ :ref: `URI Routing <routing-auto-routing-improved-configuration-options >` documentation.
315+
282316.. _controller-default-method-fallback :
283317
284318Default Method Fallback
@@ -327,40 +361,6 @@ So the default method will be passed URI segments 2 (``'101'``):
327361 Auto Routing (Improved) does not execute the method, and it results in 404
328362 Not Found.
329363
330- Default Controller
331- ==================
332-
333- The Default Controller is a special controller that is used when a URI ends with
334- a directory name or when a URI is not present, as will be the case when only your
335- site root URL is requested.
336-
337- Defining a Default Controller
338- -----------------------------
339-
340- Let's try it with the ``Helloworld `` controller.
341-
342- To specify a default controller open your **app/Config/Routes.php **
343- file and set this variable:
344-
345- .. literalinclude :: controllers/015.php
346-
347- Where ``Helloworld `` is the name of the controller class you want to be used.
348-
349- A few lines further down **Routes.php ** in the "Route Definitions" section, comment out the line:
350-
351- .. literalinclude :: controllers/016.php
352-
353- If you now browse to your site without specifying any URI segments you'll
354- see the "Hello World" message.
355-
356- .. important :: When you use Auto Routing (Improved), you must remove the line
357- ``$routes->get('/', 'Home::index'); ``. Because defined routes take
358- precedence over Auto Routing, and controllers defined in the defined routes
359- are denied access by Auto Routing (Improved) for security reasons.
360-
361- For more information, please refer to the :ref: `routes-configuration-options ` section of the
362- :ref: `URI Routing <routing-auto-routing-improved-configuration-options >` documentation.
363-
364364Organizing Your Controllers into Sub-directories
365365================================================
366366
0 commit comments