Skip to content

Commit 2250f03

Browse files
authored
Merge pull request #8312 from kenjis/docs-upgrade_routing
docs: improve upgrade_routing
2 parents 5ccb299 + a5fbda1 commit 2250f03

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

user_guide_src/source/incoming/routing.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ and the ``productLookupByID()`` method passing in the match as a variable to the
6969

7070
.. literalinclude:: routing/009.php
7171

72+
.. _routing-http-verb-routes:
73+
7274
HTTP verb Routes
7375
================
7476

@@ -185,11 +187,20 @@ Placeholders Description
185187
.. note:: ``{locale}`` cannot be used as a placeholder or other part of the route, as it is reserved for use
186188
in :doc:`localization </outgoing/localization>`.
187189

188-
Note that a single ``(:any)`` will match multiple segments in the URL if present. For example the route:
190+
.. _routing-placeholder-any:
191+
192+
The Behavior of (:any)
193+
^^^^^^^^^^^^^^^^^^^^^^
194+
195+
Note that a single ``(:any)`` will match multiple segments in the URL if present.
196+
197+
For example the route:
189198

190199
.. literalinclude:: routing/010.php
191200

192-
will match **product/123**, **product/123/456**, **product/123/456/789** and so on. The implementation in the
201+
will match **product/123**, **product/123/456**, **product/123/456/789** and so on.
202+
203+
The implementation in the
193204
Controller should take into account the maximum parameters:
194205

195206
.. literalinclude:: routing/011.php

user_guide_src/source/installation/upgrade_routing.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ What has been changed
1717
- In CI4 the Auto Routing is disabled by default.
1818
- In CI4 the new more secure :ref:`auto-routing-improved` is introduced.
1919
- In CI4 the routing is no longer configured by setting the routes as array.
20+
- The Wildcard ``(:any)`` In CI3 will be the Placeholder ``(:segment)`` in CI4. The ``(:any)`` in CI4 matches multiple segements. See :ref:`URI Routing <routing-placeholder-any>`.
2021

2122
Upgrade Guide
2223
=============
2324

2425
1. If you use the Auto Routing in the same way as CI3, you need to enable :ref:`auto-routing-legacy`.
25-
2. The placeholder ``(:any)`` in CI3 will be ``(:segment)`` in CI4.
26-
3. You have to change the syntax of each routing line and append it in **app/Config/Routes.php**. For example:
26+
2. You have to change the syntax of each routing line and append it in **app/Config/Routes.php**. For example:
2727

2828
- ``$route['journals'] = 'blogs';`` to ``$routes->add('journals', 'Blogs::index');``. This would map to the ``index()`` method in the ``Blogs`` controller.
29-
- ``$route['product/(:any)'] = 'catalog/product_lookup';`` to ``$routes->add('product/(:segment)', 'Catalog::productLookup');``
29+
- ``$route['product/(:any)'] = 'catalog/product_lookup';`` to ``$routes->add('product/(:segment)', 'Catalog::productLookup');``. Don't forget to replace ``(:any)`` with ``(:segment)``.
3030
- ``$route['login/(.+)'] = 'auth/login/$1';`` to ``$routes->add('login/(.+)', 'Auth::login/$1');``
3131

32+
.. note:: For backward compatibility, ``$routes->add()`` is used here. But we
33+
strongly recommend to use :ref:`routing-http-verb-routes` like
34+
``$routes->get()`` instead of ``$routes->add()`` for security.
35+
3236
Code Example
3337
============
3438

@@ -43,3 +47,7 @@ CodeIgniter Version 4.x
4347
Path: **app/Config/Routes.php**:
4448

4549
.. literalinclude:: upgrade_routing/001.php
50+
51+
.. note:: For backward compatibility, ``$routes->add()`` is used here. But we
52+
strongly recommend to use :ref:`routing-http-verb-routes` like
53+
``$routes->get()`` instead of ``$routes->add()`` for security.
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
<?php
22

3-
namespace Config;
3+
use CodeIgniter\Router\RouteCollection;
44

5-
// ...
6-
7-
/*
8-
* --------------------------------------------------------------------
9-
* Route Definitions
10-
* --------------------------------------------------------------------
5+
/**
6+
* @var RouteCollection $routes
117
*/
12-
13-
// ...
8+
$routes->get('/', 'Home::index');
149

1510
$routes->add('posts/index', 'Posts::index');
1611
$routes->add('teams/create', 'Teams::create');
@@ -21,5 +16,3 @@
2116
$routes->add('drivers/create', 'Drivers::create');
2217
$routes->add('drivers/update', 'Drivers::update');
2318
$routes->add('posts/(:segment)', 'Posts::view/$1');
24-
25-
// ...

0 commit comments

Comments
 (0)