@@ -359,7 +359,7 @@ routes with UTF-8 characters:
359
359
360
360
.. configuration-block ::
361
361
362
- .. code-block :: php-annotations
362
+ .. code-block :: php-annotations
363
363
364
364
// src/AppBundle/Controller/DefaultController.php
365
365
namespace AppBundle\Controller;
@@ -379,16 +379,16 @@ routes with UTF-8 characters:
379
379
// ...
380
380
}
381
381
382
- .. code-block :: yaml
382
+ .. code-block :: yaml
383
383
384
- # routes .yml
385
- route1 :
386
- path : /category/{name}
387
- defaults : { _controller: 'AppBundle:Default:category' }
388
- options :
389
- utf8 : true
384
+ # app/config/routing .yml
385
+ route1 :
386
+ path : /category/{name}
387
+ defaults : { _controller: 'AppBundle:Default:category' }
388
+ options :
389
+ utf8 : true
390
390
391
- .. code-block :: xml
391
+ .. code-block :: xml
392
392
393
393
<!-- app/config/routing.xml -->
394
394
<?xml version =" 1.0" encoding =" UTF-8" ?>
@@ -403,26 +403,26 @@ routes with UTF-8 characters:
403
403
</route >
404
404
</routes >
405
405
406
- .. code-block :: php
407
-
408
- // app/config/routing.php
409
- use Symfony\Component\Routing\RouteCollection;
410
- use Symfony\Component\Routing\Route;
411
-
412
- $collection = new RouteCollection();
413
- $collection->add('route1', new Route('/category/{name}',
414
- array(
415
- '_controller' => 'AppBundle:Default:category',
416
- ),
417
- array(),
418
- array(
419
- 'utf8' => true,
420
- )
421
- );
406
+ .. code-block :: php
407
+
408
+ // app/config/routing.php
409
+ use Symfony\Component\Routing\RouteCollection;
410
+ use Symfony\Component\Routing\Route;
411
+
412
+ $collection = new RouteCollection();
413
+ $collection->add('route1', new Route('/category/{name}',
414
+ array(
415
+ '_controller' => 'AppBundle:Default:category',
416
+ ),
417
+ array(),
418
+ array(
419
+ 'utf8' => true,
420
+ )
421
+ );
422
422
423
- // ...
423
+ // ...
424
424
425
- return $collection;
425
+ return $collection;
426
426
427
427
428
428
In this route, the ``utf8 `` option set to ``true `` makes Symfony consider the
@@ -431,9 +431,11 @@ byte character. This means that so the following URLs would match:
431
431
``/category/日本語 ``, ``/category/فارسی ``, ``/category/한국어 ``, etc. In case you
432
432
are wondering, this option also allows to include and match emojis in URLs.
433
433
434
+ You can also include UTF-8 strings as routing requirements:
435
+
434
436
.. configuration-block ::
435
437
436
- .. code-block :: php-annotations
438
+ .. code-block :: php-annotations
437
439
438
440
// src/AppBundle/Controller/DefaultController.php
439
441
namespace AppBundle\Controller;
@@ -444,32 +446,32 @@ are wondering, this option also allows to include and match emojis in URLs.
444
446
class DefaultController extends Controller
445
447
{
446
448
/**
447
- *
448
- * @Route(
449
- * "/category/{name}",
450
- * name="route2",
451
- * requirements={"default"="한국어"},
452
- * options={"utf8": true}
453
- * )
454
- *
455
- */
449
+ *
450
+ * @Route(
451
+ * "/category/{name}",
452
+ * name="route2",
453
+ * requirements={"default"="한국어"},
454
+ * options={"utf8": true}
455
+ * )
456
+ *
457
+ */
456
458
public function defaultAction()
457
459
{
458
460
// ...
459
461
}
460
462
461
- .. code-block :: yaml
463
+ .. code-block :: yaml
462
464
463
- # routes .yml
464
- route2 :
465
- path : /default/{default}
466
- defaults : { _controller: 'AppBundle:Default:default' }
467
- requirements :
468
- default : " 한국어"
469
- options :
470
- utf8 : true
465
+ # app/config/routing .yml
466
+ route2 :
467
+ path : /default/{default}
468
+ defaults : { _controller: 'AppBundle:Default:default' }
469
+ requirements :
470
+ default : " 한국어"
471
+ options :
472
+ utf8 : true
471
473
472
- .. code-block :: xml
474
+ .. code-block :: xml
473
475
474
476
<!-- app/config/routing.xml -->
475
477
<?xml version =" 1.0" encoding =" UTF-8" ?>
@@ -485,43 +487,43 @@ are wondering, this option also allows to include and match emojis in URLs.
485
487
</route >
486
488
</routes >
487
489
488
- .. code-block :: php
489
-
490
- // app/config/routing.php
491
- use Symfony\Component\Routing\RouteCollection;
492
- use Symfony\Component\Routing\Route;
493
-
494
- $collection = new RouteCollection();
495
- $collection->add('route2', new Route('/default/{default}',
496
- array(
497
- '_controller' => 'AppBundle:Default:default',
498
- ),
499
- array(
500
- 'default' => '한국어',
501
- ),
502
- array(
503
- 'utf8' => true,
504
- )
505
- );
506
-
507
- // ...
490
+ .. code-block :: php
491
+
492
+ // app/config/routing.php
493
+ use Symfony\Component\Routing\RouteCollection;
494
+ use Symfony\Component\Routing\Route;
495
+
496
+ $collection = new RouteCollection();
497
+ $collection->add('route2', new Route('/default/{default}',
498
+ array(
499
+ '_controller' => 'AppBundle:Default:default',
500
+ ),
501
+ array(
502
+ 'default' => '한국어',
503
+ ),
504
+ array(
505
+ 'utf8' => true,
506
+ )
507
+ );
508
508
509
- return $collection;
509
+ // ...
510
510
511
+ return $collection;
512
+
513
+ .. tip ::
511
514
512
- This second example describes how you can use UTF-8 strings as a routing
513
- requirements.
515
+ In addition to UTF-8 characters, the Routing component also supports all
516
+ the `PCRE Unicode properties `_, which are escape sequences that match
517
+ generic character types. For example, ``\p{Lu} `` matches any uppercase
518
+ character in any language, ``\p{Greek} `` matches any Greek character,
519
+ ``\P{Han} `` matches any character not included in the Chinese Han script.
514
520
515
521
.. note ::
516
522
517
- In Symfony 3.2 there is no need to set this ``utf8 `` option explicitly.
518
- As soon as Symfony finds a UTF-8 character in the route path or requirements,
519
- it will turn the UTF-8 support automatically. In addition to UTF-8
520
- characters, the Routing component also supports all the `PCRE Unicode properties `_,
521
- which are escape sequences that match generic character types. For
522
- example, ``\p{Lu} `` matches any uppercase character in any language,
523
- ``\p{Greek} `` matches any Greek character, ``\P{Han} `` matches any character
524
- not included in the Chinese Han script.
523
+ In Symfony 3.2 there is no need to set the ``utf8 `` option explicitly. As
524
+ soon as Symfony finds a UTF-8 character in the route path or requirements,
525
+ it will turn the UTF-8 support automatically. However, this behaviour is
526
+ deprecated and setting the option will be required in Symfony 4.0.
525
527
526
528
Learn more
527
529
----------
0 commit comments