0

I use FOSJsRoutingBundle to bring my routes to JavaScript. My controller annotation:

/* 
 * @Method("GET")
 * @Route("/search/{searchterm}", name="_api_player_search", options={"expose"=true})
 */

My JavaScript:

console.log(Routing.generate('_api_player_search', {searchterm: 'aaron', limit: 5}, true));

The output in firebug console:

undefined://undefinedundefined/api/player/search/aaron?limit=5

Testing on a local xampp server, Symfony v 2.4.2, FOSJsRoutingBundle in is actual version from 18. Feb 2014.

You see the problem? What have i done wrong?

3
  • Did you add the configuration in your app/config/routing.yml? Commented Feb 19, 2014 at 14:52
  • yeah like fos_js_routing: resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml" Commented Feb 19, 2014 at 15:12
  • Have you include in your layout? <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script> <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script> Commented Jan 22, 2017 at 5:42

1 Answer 1

1

Try to rename your route name to somthing like

/* 
 * @Route("/search/{searchterm}", 
   name="apiPlayerSearch",
   options={"expose"=true},
   methods={"GET"}
   )
 */

Then run

php app/console fos:js-routing:dump

This could work as i had a similar problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.