Skip to content

Commit af80d7b

Browse files
committed
docs: move Example up
This is easier to understand, and the explanation for (:any) is easier to find.
1 parent 0fbc883 commit af80d7b

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

user_guide_src/source/incoming/routing.rst

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,42 @@ If you expect a GET request, you use the ``get()`` method:
3232
.. literalinclude:: routing/001.php
3333

3434
A route takes the URI path (``/``) on the left, and maps it to the controller and method (``Home::index``) on the right,
35-
along with any parameters that should be passed to the controller. The controller and method should
35+
along with any parameters that should be passed to the controller.
36+
37+
The controller and method should
3638
be listed in the same way that you would use a static method, by separating the class
37-
and its method with a double-colon, like ``Users::list``. If that method requires parameters to be
39+
and its method with a double-colon, like ``Users::list``.
40+
41+
If that method requires parameters to be
3842
passed to it, then they would be listed after the method name, separated by forward-slashes:
3943

4044
.. literalinclude:: routing/002.php
4145

46+
Examples
47+
========
48+
49+
Here are a few basic routing examples.
50+
51+
A URL containing the word **journals** in the first segment will be mapped to the ``\App\Controllers\Blogs`` class,
52+
and the default method, which is usually ``index()``:
53+
54+
.. literalinclude:: routing/006.php
55+
56+
A URL containing the segments **blog/joe** will be mapped to the ``\App\Controllers\Blogs`` class and the ``users()`` method.
57+
The ID will be set to ``34``:
58+
59+
.. literalinclude:: routing/007.php
60+
61+
A URL with **product** as the first segment, and anything in the second will be mapped to the ``\App\Controllers\Catalog`` class
62+
and the ``productLookup()`` method:
63+
64+
.. literalinclude:: routing/008.php
65+
66+
A URL with **product** as the first segment, and a number in the second will be mapped to the ``\App\Controllers\Catalog`` class
67+
and the ``productLookupByID()`` method passing in the match as a variable to the method:
68+
69+
.. literalinclude:: routing/009.php
70+
4271
HTTP verbs
4372
==========
4473

@@ -99,31 +128,6 @@ Placeholders Description
99128
.. note:: ``{locale}`` cannot be used as a placeholder or other part of the route, as it is reserved for use
100129
in :doc:`localization </outgoing/localization>`.
101130

102-
Examples
103-
========
104-
105-
Here are a few basic routing examples.
106-
107-
A URL containing the word **journals** in the first segment will be mapped to the ``\App\Controllers\Blogs`` class,
108-
and the default method, which is usually ``index()``:
109-
110-
.. literalinclude:: routing/006.php
111-
112-
A URL containing the segments **blog/joe** will be mapped to the ``\App\Controllers\Blogs`` class and the ``users()`` method.
113-
The ID will be set to ``34``:
114-
115-
.. literalinclude:: routing/007.php
116-
117-
A URL with **product** as the first segment, and anything in the second will be mapped to the ``\App\Controllers\Catalog`` class
118-
and the ``productLookup()`` method:
119-
120-
.. literalinclude:: routing/008.php
121-
122-
A URL with **product** as the first segment, and a number in the second will be mapped to the ``\App\Controllers\Catalog`` class
123-
and the ``productLookupByID()`` method passing in the match as a variable to the method:
124-
125-
.. literalinclude:: routing/009.php
126-
127131
Note that a single ``(:any)`` will match multiple segments in the URL if present. For example the route:
128132

129133
.. literalinclude:: routing/010.php

0 commit comments

Comments
 (0)