@@ -703,117 +703,9 @@ Adding a Hostname Pattern
703
703
.. versionadded :: 2.2
704
704
Hostname matching support was added in Symfony 2.2
705
705
706
- You can also match on the HTTP *hostname * of the incoming request:
707
-
708
- .. configuration-block ::
709
-
710
- .. code-block :: yaml
711
-
712
- mobile_homepage :
713
- pattern : /
714
- hostname_pattern : m.example.com
715
- defaults : { _controller: AcmeDemoBundle:Main:mobileHomepage }
716
-
717
- homepage :
718
- pattern : /
719
- defaults : { _controller: AcmeDemoBundle:Main:homepage }
720
-
721
- .. code-block :: xml
722
-
723
- <?xml version =" 1.0" encoding =" UTF-8" ?>
724
-
725
- <routes xmlns =" http://symfony.com/schema/routing"
726
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
727
- xsi : schemaLocation =" http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd" >
728
-
729
- <route id =" mobile_homepage" pattern =" /" hostname-pattern =" m.example.com" >
730
- <default key =" _controller" >AcmeDemoBundle:Main:mobileHomepage</default >
731
- </route >
732
-
733
- <route id =" homepage" pattern =" /" >
734
- <default key =" _controller" >AcmeDemoBundle:Main:homepage</default >
735
- </route >
736
- </routes >
737
-
738
- .. code-block :: php
739
-
740
- use Symfony\Component\Routing\RouteCollection;
741
- use Symfony\Component\Routing\Route;
742
-
743
- $collection = new RouteCollection();
744
- $collection->add('mobile_homepage', new Route('/', array(
745
- '_controller' => 'AcmeDemoBundle:Main:mobileHomepage',
746
- ), array(), array(), 'm.example.com'));
747
-
748
- $collection->add('homepage', new Route('/', array(
749
- '_controller' => 'AcmeDemoBundle:Main:homepage',
750
- )));
751
-
752
- return $collection;
753
-
754
- Both routes match the same pattern ``/ ``, however the first one will match
755
- only if the hostname is ``m.example.com ``.
756
-
757
- Placeholders and Requirements in Hostname Patterns
758
- --------------------------------------------------
759
-
760
- Placeholders can be used in hostname patterns as well as in patterns, and
761
- requirements also apply to them.
762
-
763
- In the following example we avoid hardcoding the domain name by using a
764
- placeholder and a requirement. ``%domain% `` in requirements is replaced
765
- by the value of the ``domain `` dependency injection container parameter.
766
-
767
- .. configuration-block ::
768
-
769
- .. code-block :: yaml
770
-
771
- mobile_homepage :
772
- pattern : /
773
- hostname_pattern : m.{domain}
774
- defaults : { _controller: AcmeDemoBundle:Main:mobileHomepage }
775
- requirements :
776
- domain : %domain%
777
-
778
- homepage :
779
- pattern : /
780
- defaults : { _controller: AcmeDemoBundle:Main:homepage }
781
-
782
- .. code-block :: xml
783
-
784
- <?xml version =" 1.0" encoding =" UTF-8" ?>
785
-
786
- <routes xmlns =" http://symfony.com/schema/routing"
787
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
788
- xsi : schemaLocation =" http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd" >
789
-
790
- <route id =" mobile_homepage" pattern =" /" hostname-pattern =" m.example.com" >
791
- <default key =" _controller" >AcmeDemoBundle:Main:mobileHomepage</default >
792
- <requirement key =" domain" >%domain%</requirement >
793
- </route >
794
-
795
- <route id =" homepage" pattern =" /" >
796
- <default key =" _controller" >AcmeDemoBundle:Main:homepage</default >
797
- </route >
798
- </routes >
799
-
800
- .. code-block :: php
801
-
802
- use Symfony\Component\Routing\RouteCollection;
803
- use Symfony\Component\Routing\Route;
804
-
805
- $collection = new RouteCollection();
806
- $collection->add('mobile_homepage', new Route('/', array(
807
- '_controller' => 'AcmeDemoBundle:Main:mobileHomepage',
808
- ), array(
809
- 'domain' => '%domain%',
810
- ), array(), 'm.{domain}'));
811
-
812
- $collection->add('homepage', new Route('/', array(
813
- '_controller' => 'AcmeDemoBundle:Main:homepage',
814
- )));
815
-
816
- return $collection;
706
+ You can also match on the HTTP *hostname * of the incoming request. For more
707
+ information, see :doc: `/components/routing/hostname_pattern ` in the Routing
708
+ component documentation.
817
709
818
710
.. index ::
819
711
single: Routing; Advanced example
@@ -1137,53 +1029,20 @@ instead of simply ``/hello/{name}``:
1137
1029
The string ``/admin `` will now be prepended to the pattern of each route
1138
1030
loaded from the new routing resource.
1139
1031
1032
+ .. tip ::
1033
+
1034
+ You can also define routes using annotations. See the
1035
+ :doc: `FrameworkExtraBundle documentation</bundles/SensioFrameworkExtraBundle/annotations/routing> `
1036
+ to see how.
1037
+
1140
1038
Adding a Hostname Pattern to Imported Routes
1141
1039
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1142
1040
1143
1041
.. versionadded :: 2.2
1144
1042
Hostname matching support was added in Symfony 2.2
1145
1043
1146
- You can set a hostname pattern on imported routes:
1147
-
1148
- .. configuration-block ::
1149
-
1150
- .. code-block :: yaml
1151
-
1152
- # app/config/routing.yml
1153
- acme_hello :
1154
- resource : " @AcmeHelloBundle/Resources/config/routing.yml"
1155
- hostname_pattern : " hello.example.com"
1156
-
1157
- .. code-block :: xml
1158
-
1159
- <!-- app/config/routing.xml -->
1160
- <?xml version =" 1.0" encoding =" UTF-8" ?>
1161
-
1162
- <routes xmlns =" http://symfony.com/schema/routing"
1163
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1164
- xsi : schemaLocation =" http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd" >
1165
-
1166
- <import resource =" @AcmeHelloBundle/Resources/config/routing.xml" hostname-pattern =" hello.example.com" />
1167
- </routes >
1168
-
1169
- .. code-block :: php
1170
-
1171
- // app/config/routing.php
1172
- use Symfony\Component\Routing\RouteCollection;
1173
-
1174
- $collection = new RouteCollection();
1175
- $collection->addCollection($loader->import("@AcmeHelloBundle/Resources/config/routing.php"), '', array(), array(), array(), 'hello.example.com');
1176
-
1177
- return $collection;
1178
-
1179
- The hostname pattern ``hello.example.com `` will be set on each route
1180
- loaded from the new routing resource.
1181
-
1182
- .. tip ::
1183
-
1184
- You can also define routes using annotations. See the
1185
- :doc: `FrameworkExtraBundle documentation</bundles/SensioFrameworkExtraBundle/annotations/routing> `
1186
- to see how.
1044
+ You can set a hostname pattern on imported routes. For more information,
1045
+ see :ref: `component-routing-hostname-imported `.
1187
1046
1188
1047
.. index ::
1189
1048
single: Routing; Debugging
0 commit comments