FOSJSRoutingBundle : "Route xxx does not exist"

I'm facing a really weird problem with FOSJSRoutingBundle :

First of all, here is my configuration : I'm working on Symfony 2.0.23 and with JQuery, on Windows 7 64 bits with a WAMP (Apache 2.4.2 and PHP 5.4.3). I've done all the settings from the FOSJSRoutingBundle's github and haved exposed my routes ( almost all the related problems I could find by googling (on FOSJSRoutingBundle's github,here and on different forums) were because people have not exposed their routes, but I tried php app/console fos:js-routing:debug and I do see my routes). The js is added to the layout (code of the layout at the end).

Trying to generate url for routes in js, at the beginning I wanted to generate two different routes but for test I created the js code below :

//Code inside this function is working
$("select").change(function () {
  test1=Routing.generate('myBundle_step3', { myParam: param });
//Code inside this one is also working
$('input[type="checkbox"]').change(function() {
//This is not working

With this code, I get the javaScript error "The route myBundle_step2 does not exist". Though the first part still works (alert gives me the link created and the redirection goes well). If I remove the second function, I do not get the Javascript error anymore. If in the second function I replace step2 by step3, the error becomes "The route myBundle_step3 does not exist". I tried to clear the cache and to run php app/console asset:install --symlink again, but no results.

Here is the controller corresponding code (the real code is a bit long and I don't think it's relevant, if you think so, I could put it anyways :

namespace my\Bundle\Controller;
class IndividuController extends Controller
  public function step2Action() {
    Some code
  public function step3Action($myParam) {
    Some code

The routing.yml config file relative to the bundle :

  pattern: /step/2
  defaults: {_controller: myBundle:Individu:step2}
    expose: true
  pattern: /step/3/{myParam}
  defaults: {_controller: myBundle:Individu:step3}
    expose: true

The app/config/routing.yml file :

  resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

  resource: "@myBundle/Resources/config/routing.yml"
  prefix:   /

The layout's relevant informations :

 <!-- jQuery via Google + local fallback, see -->
    <script src="//">    </script>
    <script>window.jQuery || document.write('<script src="js/jquery-1.7.1.min.js"><\/script>')</script>
       {% javascripts 'bootstrap/js/bootstrap.js'
                    'bundles/crrisuaps/js/suaps.js' %}
           <script type="text/javascript" src="{{ asset_url }}"></script>
       {% endjavascripts %}
    <script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>

Result of php app/console router:debug (I left only the relevant informations + I left the undefined variable notice just in case, it's a notice I got since I added this library, still the library works and I do not think the problem could come from here :

C:\wamp\www\suapsRepo\suaps>php app/console router:debug

Notice: Undefined variable: kPathUrl in C:\wamp\www\suapsRepo\suaps\vendor\html2
pdf\_class\tcpdfConfig.php on line 80

Call Stack:
   0.0070     231536   1. {main}() C:\wamp\www\suapsRepo\suaps\app\console:0
   0.0209     685656   2. require_once('C:\wamp\www\suapsRepo\suaps\app\bootstr
ap.php.cache') C:\wamp\www\suapsRepo\suaps\app\console:10
   0.0212     701752   3. require_once('C:\wamp\www\suapsRepo\suaps\app\autoloa
d.php') C:\wamp\www\suapsRepo\suaps\app\bootstrap.php.cache:3
   0.1335    2998152   4. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\html2pdf.class.php') C:\wamp\www\suapsRepo\suaps\app\autoload.php:51
   0.1379    3361792   5. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\_class\myPdf.class.php') C:\wamp\www\suapsRepo\suaps\vendor\html2pdf\html2p
   0.1385    3393792   6. require_once('C:\wamp\www\suapsRepo\suaps\vendor\html
2pdf\_class\tcpdfConfig.php') C:\wamp\www\suapsRepo\suaps\vendor\html2pdf\_class

[router] Current routes
Name                                            Method Pattern
_assetic_55f0319                                ANY    /css/55f0319.css
_assetic_55f0319_0                              ANY    /css/55f0319_bootstrap_1.
_assetic_55f0319_1                              ANY    /css/55f0319_bootstrap-re
_assetic_55f0319_2                              ANY    /css/55f0319_style_3.css
_assetic_3608a04                                ANY    /js/3608a04.js
_assetic_3608a04_0                              ANY    /js/3608a04_bootstrap_1.j
_assetic_3608a04_1                              ANY    /js/3608a04_router_2.js
_assetic_3608a04_2                              ANY    /js/3608a04_suaps_3.js

fos_js_routing_js                               ANY    /js/routing.{_format}
myBundle_homepage                        ANY    /

myBundle_inscription_etape1              ANY    /inscription/etape/1
myBundle_inscription_etape2              ANY    /inscription/etape/2
myBundle_inscription_etape3              ANY    /inscription/etape/3/{dis

Result of php app/console fos:js-routing:debug (I removed the PHP Notice but it happens on every command I make btw) :

C:\wamp\www\suapsRepo\suaps>php app/console fos:js-routing:debug
[router] Current routes
Name                               Method Pattern
crrisuapsBundle_inscription_etape2 ANY    /inscription/etape/2
crrisuapsBundle_inscription_etape3 ANY    /inscription/etape/3/{disciplineSelect

Edit : Also, don't know if it's relevant but when I try 'php app/console fos:js-routing:debug myBundle_step2' I get the following php error :

[Error Exception] Warning: Missing argument 3 for Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand:outputRoute(), called in C:\symfonyDirectory\vendor\bundles\FOS\JsRoutingBundle\Command\RouterDebugExposedCommand.php on line 62 and defined in C:\serverDirectory\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand.php line 98


I also had this problem. Setting the options.expose parameter on the routing configuration solved it for me.


    pattern:  /Cart/edit
    defaults: { _controller: CartCartBundle:Default:cart_edit }
        expose: true


var url = Routing.generate('cart_edit');
$.post(url, function(data) {
      //do somthing

Change as needed. Hope this will solve your problem.

I had the same issue and the problem was in my config file. Try checking for this:

# app/config/config.yml
    routes_to_expose: [ myBundle_step2, myBundle_step3, ... ]

Just for completeness: it is also possible to use annotations (options={"expose"=true}) as explained in the documentation:

// src/AppBundle/Controller/DefaultController.php

 * @Route("/foo/{id}/bar", options={"expose"=true}, name="my_route_to_expose")
public function indexAction($foo) {
    // ...

This also works for routes sets at controller level (example from one of my controllers):

 * Channel controller.
 * @Route("account/{account}/todos", options={"expose"=true})
 * @ParamConverter("account", class="AppBundle:Account", options={
 *     "repository_method" = "findOneById",
 *     "mapping": {"account": "id"},
 *     "map_method_signature" = true
 * })
class TodoListController extends Controller

Need Your Help

Sharing a variable between multiple different threads

java multithreading synchronization shared

I want to share a variable between multiple threads like this: