Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSJsRoutingBundle dont recognize route

I'm trying use FOSJsRoutingBundle to generate urls from symfony routes. I follow the doc.

I include the files into my base.html.twig:

{% block scripting %}
...
<script type="text/javascript" src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>        
...
{% endblock %}

And don't get inclusion error. But the try to generate an url fails:

console.log(Routing.generate('usuarios_crear'));

GET http://appsmanantiales.local/web/app_dev.php/js/routing?callback=fos.Router.setData 500 (Internal Server Error) listar:131 Uncaught Error: The route "usuarios_crear" does not exist. router.js:9

In my routing.yml I have:

usuarios_crear:
    pattern: /AbmUsuarios/crear
    defaults: { _controller: AbmBundle:Usuario:crear }
    options:
        expose: true

And the route is in php app/console fos:js-routing:debug list:

usuarios_crear ANY ANY ANY /AbmUsuarios/crear

Any ideas?

like image 889
ramiromd Avatar asked Jan 11 '14 03:01

ramiromd


3 Answers

Your code is great.

I suggest that you open an issue here, this is very likely to be a bug as you're not the only one to have that issue.

like image 183
Mick Avatar answered Nov 04 '22 22:11

Mick


It's probably easier than you think. Visit the page generated here: {{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }} it should have json-encoded list of your exposed routes. If your route is there you're good.

How check when you execute console.log(Routing.generate('usuarios_crear')); The document should be ready before you try that. So make sure it is (i.e. jQuery's $('document').ready()).

like image 24
Uriziel Avatar answered Nov 04 '22 21:11

Uriziel


Reading the Github issues, found this where the author suggest not use the dev-master version. I do a downgrade to "@stable", and works (for now). The composer.json line may be:

"friendsofsymfony/jsrouting-bundle": "@stable"

For more detail: The full install guide.

like image 41
ramiromd Avatar answered Nov 04 '22 23:11

ramiromd