Skip to content

Commit a51b07c

Browse files
authored
Merge pull request #6451 from kenjis/fix-docs-routing-namespace
docs: add about controllers namespace in routing
2 parents cd4bc83 + e046890 commit a51b07c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

user_guide_src/source/incoming/routing.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ You can supply multiple verbs that a route should match by passing them in as an
4747

4848
.. literalinclude:: routing/004.php
4949

50+
Controller's Namespace
51+
======================
52+
53+
If a controller name is stated without beginning with ``\``, the :ref:`routing-default-namespace` will be prepended:
54+
55+
.. literalinclude:: routing/063.php
56+
57+
If you put ``\`` at the beginning, it is treated as a fully qualified class name:
58+
59+
.. literalinclude:: routing/064.php
60+
61+
You can also specify the namespace with the ``namespace`` option:
62+
63+
.. literalinclude:: routing/038.php
64+
65+
See :ref:`assigning-namespace` for details.
66+
5067
Placeholders
5168
============
5269

@@ -394,7 +411,7 @@ You specify an array for the filter value:
394411
Assigning Namespace
395412
-------------------
396413

397-
While a default namespace will be prepended to the generated controllers (see below), you can also specify
414+
While a :ref:`routing-default-namespace` will be prepended to the generated controllers, you can also specify
398415
a different namespace to be used in any options array, with the ``namespace`` option. The value should be the
399416
namespace you want modified:
400417

@@ -480,6 +497,8 @@ Routes Configuration Options
480497
The RoutesCollection class provides several options that affect all routes, and can be modified to meet your
481498
application's needs. These options are available at the top of **app/Config/Routes.php**.
482499

500+
.. _routing-default-namespace:
501+
483502
Default Namespace
484503
=================
485504

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// Routes to \App\Controllers\Api\Users::update()
4+
$routes->post('api/users', 'Api\Users::update');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// Routes to \Acme\Blog\Controllers\Home::list()
4+
$routes->get('blog', '\Acme\Blog\Controllers\Home::list');

0 commit comments

Comments
 (0)