Skip to content

Commit 6c1f879

Browse files
committed
docs: move section up
1 parent af3864a commit 6c1f879

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

user_guide_src/source/incoming/controllers.rst

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,40 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
274274

275275
.. literalinclude:: controllers/022.php
276276

277+
Default Controller
278+
==================
279+
280+
The Default Controller is a special controller that is used when a URI ends with
281+
a directory name or when a URI is not present, as will be the case when only your
282+
site root URL is requested.
283+
284+
Defining a Default Controller
285+
-----------------------------
286+
287+
Let's try it with the ``Helloworld`` controller.
288+
289+
To specify a default controller open your **app/Config/Routes.php**
290+
file and set this variable:
291+
292+
.. literalinclude:: controllers/015.php
293+
294+
Where ``Helloworld`` is the name of the controller class you want to be used.
295+
296+
A few lines further down **Routes.php** in the "Route Definitions" section, comment out the line:
297+
298+
.. literalinclude:: controllers/016.php
299+
300+
If you now browse to your site without specifying any URI segments you'll
301+
see the "Hello World" message.
302+
303+
.. important:: When you use Auto Routing (Improved), you must remove the line
304+
``$routes->get('/', 'Home::index');``. Because defined routes take
305+
precedence over Auto Routing, and controllers defined in the defined routes
306+
are denied access by Auto Routing (Improved) for security reasons.
307+
308+
For more information, please refer to the :ref:`routes-configuration-options` section of the
309+
:ref:`URI Routing <routing-auto-routing-improved-configuration-options>` documentation.
310+
277311
.. _controller-default-method-fallback:
278312

279313
Default Method Fallback
@@ -322,40 +356,6 @@ So the default method will be passed URI segments 2 (``'101'``):
322356
Auto Routing (Improved) does not execute the method, and it results in 404
323357
Not Found.
324358

325-
Default Controller
326-
==================
327-
328-
The Default Controller is a special controller that is used when a URI ends with
329-
a directory name or when a URI is not present, as will be the case when only your
330-
site root URL is requested.
331-
332-
Defining a Default Controller
333-
-----------------------------
334-
335-
Let's try it with the ``Helloworld`` controller.
336-
337-
To specify a default controller open your **app/Config/Routes.php**
338-
file and set this variable:
339-
340-
.. literalinclude:: controllers/015.php
341-
342-
Where ``Helloworld`` is the name of the controller class you want to be used.
343-
344-
A few lines further down **Routes.php** in the "Route Definitions" section, comment out the line:
345-
346-
.. literalinclude:: controllers/016.php
347-
348-
If you now browse to your site without specifying any URI segments you'll
349-
see the "Hello World" message.
350-
351-
.. important:: When you use Auto Routing (Improved), you must remove the line
352-
``$routes->get('/', 'Home::index');``. Because defined routes take
353-
precedence over Auto Routing, and controllers defined in the defined routes
354-
are denied access by Auto Routing (Improved) for security reasons.
355-
356-
For more information, please refer to the :ref:`routes-configuration-options` section of the
357-
:ref:`URI Routing <routing-auto-routing-improved-configuration-options>` documentation.
358-
359359
Organizing Your Controllers into Sub-directories
360360
================================================
361361

0 commit comments

Comments
 (0)