33
44Add these two lines in your layout:
55
6- .. code-block :: twig
6+ .. configuration-block ::
7+
8+ .. code-block :: html+twig
9+
10+ <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
11+ <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
12+
13+ .. code-block :: html+php
714
8- <script src="{{ asset ('bundles/fosjsrouting/js/router.js') }} "></script>
9- <script src="{{ path ('fos_js_routing_js', {" callback": " fos.Router.setData"}) }} "></script>
15+ <script src="<?php echo $view['assets']->getUrl ('bundles/fosjsrouting/js/router.js') ?> "></script>
16+ <script src="<?php echo $view['router']->generate ('fos_js_routing_js', array(' callback' => ' fos.Router.setData')) ?> "></script>
1017
1118.. note ::
1219
@@ -20,39 +27,52 @@ It's as simple as calling:
2027
2128.. code-block :: javascript
2229
23- Routing .generate (' route_id ' , /* your params */ )
30+ Routing .generate (' route_name ' , /* your params */ )
2431
2532 Or if you want to generate **absolute URLs **:
2633
2734.. code-block :: javascript
2835
29- Routing .generate (' route_id ' , /* your params */ , true )
36+ Routing .generate (' route_name ' , /* your params */ , true )
3037
3138 Assuming some route definitions:
3239
3340.. configuration-block ::
3441
3542 .. code-block :: php-annotations
3643
37- // src/Acme/DemoBundle /Controller/DefaultController.php
44+ // src/AppBundle /Controller/DefaultController.php
3845
3946 /**
40- * @Route("/foo/{id}/bar", name="my_route_to_expose", options={"expose"=true})
47+ * @Route("/foo/{id}/bar", options={"expose"=true}, name="my_route_to_expose" )
4148 */
42- public function exposedAction($foo)
49+ public function indexAction($foo) {
50+ // ...
51+ }
52+
53+ /**
54+ * @Route("/blog/{page}",
55+ * defaults = { "page" = 1 },
56+ * options = { "expose" = true },
57+ * name = "my_route_to_expose_with_defaults",
58+ * )
59+ */
60+ public function blogAction($page) {
61+ // ...
62+ }
4363
4464 .. code-block :: yaml
4565
4666 # app/config/routing.yml
4767 my_route_to_expose :
4868 pattern : /foo/{id}/bar
49- defaults : { _controller: HelloBundle:Hello :index }
69+ defaults : { _controller: AppBundle:Default :index }
5070 options :
5171 expose : true
5272
5373 my_route_to_expose_with_defaults :
5474 pattern : /blog/{page}
55- defaults : { _controller: AcmeBlogBundle:Blog:index , page: 1 }
75+ defaults : { _controller: AppBundle:Default:blog , page: 1 }
5676 options :
5777 expose : true
5878
@@ -119,62 +139,3 @@ You can enable HTTP caching as below:
119139 smaxage : null # integer value, e.g. 300
120140 expires : null # anything that can be fed to "new \DateTime($expires)", e.g. "5 minutes"
121141 vary : [] # string or array, e.g. "Cookie" or [ Cookie, Accept ]
122-
123- Commands
124- --------
125-
126- fos:js-routing: dump
127- ~~~~~~~~~~~~~~~~~~~
128-
129- This command dumps the route information into a file so that instead of having
130- the controller generated JavaScript, you can use a normal file. This also allows
131- to combine the routes with the other JavaScript files in assetic.
132-
133- .. code-block :: bash
134-
135- $ php app/console fos:js-routing:dump
136-
137- Instead of the line
138-
139- .. code-block :: twig
140-
141- <script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
142-
143- you now include this as
144-
145- .. code-block :: html
146-
147- <script src =" /js/fos_js_routes.js" ></script >
148-
149- Or inside assetic, do
150-
151- .. code-block :: twig
152-
153- {% javascripts filter='?yui_js'
154- 'bundles/fosjsrouting/js/router.js'
155- 'js/fos_js_routes.js'
156- %}
157- <script src="{{ asset_url }}"></script>
158- {% endjavascripts %}
159-
160- .. caution ::
161-
162- You should follow the Symfony documentation about generating URLs
163- in the console: `Configuring The Request Context Globally `_.
164-
165- .. tip ::
166-
167- If you are using JMSI18nRoutingBundle, you need to run the command with the
168- ``--locale `` parameter once for each locale you use and adjust your include
169- paths accordingly.
170-
171- fos:js-routing: debug
172- ~~~~~~~~~~~~~~~~~~~~
173-
174- This command lists all exposed routes:
175-
176- .. code-block :: bash
177-
178- $ php app/console fos:js-routing:debug [name]
179-
180- .. _`Configuring The Request Context Globally` : http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally
0 commit comments