@@ -34,14 +34,15 @@ your autoloader to load the Routing component::
34
34
use Symfony\Component\Routing\RouteCollection;
35
35
use Symfony\Component\Routing\Route;
36
36
37
+ $route = new Route('/foo', array('controller' => 'MyController'))
37
38
$routes = new RouteCollection();
38
- $routes->add('route_name', new Route('/foo', array('controller' => 'MyController')) );
39
+ $routes->add('route_name', $route );
39
40
40
41
$context = new RequestContext($_SERVER['REQUEST_URI']);
41
42
42
43
$matcher = new UrlMatcher($routes, $context);
43
44
44
- $parameters = $matcher->match('/foo');
45
+ $parameters = $matcher->match('/foo');
45
46
// array('controller' => 'MyController', '_route' => 'route_name')
46
47
47
48
.. note ::
@@ -97,7 +98,11 @@ Take the following route, which combines several of these ideas::
97
98
// ...
98
99
99
100
$parameters = $matcher->match('/archive/2012-01');
100
- // array('controller' => 'showArchive', 'month' => '2012-01', '_route' => ...)
101
+ // array(
102
+ // 'controller' => 'showArchive',
103
+ // 'month' => '2012-01',
104
+ // '_route' => ...
105
+ // )
101
106
102
107
$parameters = $matcher->match('/archive/foo');
103
108
// throws ResourceNotFoundException
@@ -115,15 +120,22 @@ you can define:
115
120
For example, the following route would only accept requests to /foo with
116
121
the POST method and a secure connection::
117
122
118
- $route = new Route('/foo', array(), array('_method' => 'post', '_scheme' => 'https' ));
123
+ $route = new Route(
124
+ '/foo',
125
+ array(),
126
+ array('_method' => 'post', '_scheme' => 'https' )
127
+ );
119
128
120
129
.. tip ::
121
130
122
131
If you want to match all urls which start with a certain path and end in an
123
132
arbitrary suffix you can use the following route definition::
124
133
125
- $route = new Route('/start/{suffix}', array('suffix' => ''), array('suffix' => '.*'));
126
-
134
+ $route = new Route(
135
+ '/start/{suffix}',
136
+ array('suffix' => ''),
137
+ array('suffix' => '.*')
138
+ );
127
139
128
140
Using Prefixes
129
141
~~~~~~~~~~~~~~
@@ -139,7 +151,11 @@ default requirements and default options to all routes of a subtree::
139
151
$subCollection->add(...);
140
152
$subCollection->add(...);
141
153
142
- $rootCollection->addCollection($subCollection, '/prefix', array('_scheme' => 'https'));
154
+ $rootCollection->addCollection(
155
+ $subCollection,
156
+ '/prefix',
157
+ array('_scheme' => 'https')
158
+ );
143
159
144
160
Set the Request Parameters
145
161
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -148,14 +164,21 @@ The :class:`Symfony\\Component\\Routing\\RequestContext` provides information
148
164
about the current request. You can define all parameters of an HTTP request
149
165
with this class via its constructor::
150
166
151
- public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443)
167
+ public function __construct(
168
+ $baseUrl = '',
169
+ $method = 'GET',
170
+ $host = 'localhost',
171
+ $scheme = 'http',
172
+ $httpPort = 80,
173
+ $httpsPort = 443
174
+ )
152
175
153
176
.. _components-routing-http-foundation :
154
177
155
178
Normally you can pass the values from the ``$_SERVER `` variable to populate the
156
179
:class: `Symfony\\ Component\\ Routing\\ RequestContext `. But If you use the
157
- :doc: `HttpFoundation</components/http_foundation/index> ` component, you can use its
158
- :class: `Symfony\\ Component\\ HttpFoundation\\ Request ` class to feed the
180
+ :doc: `HttpFoundation</components/http_foundation/index> ` component, you can use its
181
+ :class: `Symfony\\ Component\\ HttpFoundation\\ Request ` class to feed the
159
182
:class: `Symfony\\ Component\\ Routing\\ RequestContext ` in a shortcut::
160
183
161
184
use Symfony\Component\HttpFoundation\Request;
@@ -242,7 +265,10 @@ have to provide the name of a php file which returns a :class:`Symfony\\Componen
242
265
use Symfony\Component\Routing\Route;
243
266
244
267
$collection = new RouteCollection();
245
- $collection->add('route_name', new Route('/foo', array('controller' => 'ExampleController')));
268
+ $collection->add(
269
+ 'route_name',
270
+ new Route('/foo', array('controller' => 'ExampleController'))
271
+ );
246
272
// ...
247
273
248
274
return $collection;
@@ -278,7 +304,13 @@ The :class:`Symfony\\Component\\Routing\\Router` class is a all-in-one package
278
304
to quickly use the Routing component. The constructor expects a loader instance,
279
305
a path to the main route definition and some other settings::
280
306
281
- public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array());
307
+ public function __construct(
308
+ LoaderInterface $loader,
309
+ $resource,
310
+ array $options = array(),
311
+ RequestContext $context = null,
312
+ array $defaults = array()
313
+ );
282
314
283
315
With the ``cache_dir `` option you can enable route caching (if you provide a
284
316
path) or disable caching (if it's set to ``null ``). The caching is done
0 commit comments