@@ -24,11 +24,21 @@ Symfony provides several route loaders for the most common needs:
24
24
# loads routes from the given routing file stored in some bundle
25
25
resource : ' @AcmeBundle/Resources/config/routing.yaml'
26
26
27
+ app_psr4 :
28
+ # loads routes from the PHP attributes of the controllers found in the given PSR-4 namespace root
29
+ resource : ' ../src/Controller/'
30
+ type : psr4@App\Controller
31
+
27
32
app_attributes :
28
33
# loads routes from the PHP attributes of the controllers found in that directory
29
34
resource : ' ../src/Controller/'
30
35
type : attribute
31
36
37
+ app_class_attributes :
38
+ # loads routes from the PHP attributes of the given class
39
+ resource : App\Controller\MyController
40
+ type : attribute
41
+
32
42
app_directory :
33
43
# loads routes from the YAML, XML or PHP files found in that directory
34
44
resource : ' ../legacy/routing/'
@@ -51,9 +61,15 @@ Symfony provides several route loaders for the most common needs:
51
61
<!-- loads routes from the given routing file stored in some bundle -->
52
62
<import resource =" @AcmeBundle/Resources/config/routing.yaml" />
53
63
64
+ <!-- loads routes from the PHP attributes of the controllers found in the given PSR-4 namespace root -->
65
+ <import resource =" ../src/Controller/" type =" psr4@App\Controller" />
66
+
54
67
<!-- loads routes from the PHP attributes of the controllers found in that directory -->
55
68
<import resource =" ../src/Controller/" type =" attribute" />
56
69
70
+ <!-- loads routes from the PHP attributes of the given class -->
71
+ <import resource =" App\Controller\MyController" type =" attribute" />
72
+
57
73
<!-- loads routes from the YAML or XML files found in that directory -->
58
74
<import resource =" ../legacy/routing/" type =" directory" />
59
75
@@ -70,9 +86,16 @@ Symfony provides several route loaders for the most common needs:
70
86
// loads routes from the given routing file stored in some bundle
71
87
$routes->import('@AcmeBundle/Resources/config/routing.yaml');
72
88
89
+ // loads routes from the PHP attributes (#[Route(...)])
90
+ // of the controllers found in in the given PSR-4 namespace root
91
+ $routes->import('../src/Controller/', 'psr4@App\Controller');
92
+
73
93
// loads routes from the PHP attributes (#[Route(...)]) of the controllers found in that directory
74
94
$routes->import('../src/Controller/', 'attribute');
75
95
96
+ // loads routes from the PHP attributes (#[Route(...)]) of the given class
97
+ $routes->import('App\Controller\MyController', 'attribute');
98
+
76
99
// loads routes from the YAML or XML files found in that directory
77
100
$routes->import('../legacy/routing/', 'directory');
78
101
@@ -85,6 +108,10 @@ Symfony provides several route loaders for the most common needs:
85
108
The ``attribute `` value of the second argument of ``import() `` was introduced
86
109
in Symfony 6.1.
87
110
111
+ .. versionadded :: 6.2
112
+
113
+ The ``psr4 `` resource type was introduced in Symfony 6.2.
114
+
88
115
.. note ::
89
116
90
117
When importing resources, the key (e.g. ``app_file ``) is the name of the collection.
0 commit comments