FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Problem with fos.Router.setData #383

Closed ghost closed 12 months ago

ghost commented 4 years ago

Dear, When i put "" in my twig, it generate an error. And when i go to the url http://domain.com/js/routing?callback=fos.Router.setData it render an route.

Why ?

Thanks !

stof commented 4 years ago

what do you mean by it render a route ?

ghost commented 4 years ago

Hello @stof, attached a screenshot. Capture

HamzaRouissi commented 3 years ago

hello @florianproxi can you tell me how did you configure the FOsJSRoutingBundle with symfony 5?

stof commented 3 years ago

well, this seems to be going to your own controller, not to the controller of FOsJSRoutingBundle. So something looks wrong with the route definitions in your project.

HamzaRouissi commented 3 years ago

@stof Hello.. can you tell me how did you configure the FOsJSRoutingBundle with symfony.. The documentation is missing the configuration with tha version 5...

stof commented 3 years ago

exactly the same than for other versions.

HamzaRouissi commented 3 years ago

@stof i folow the documentation so the version 5 is different than others , this how i configure the fosjs in my project : config/packages/routing.yaml:

framework:
    router:
        utf8: true

        # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
        # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
        #default_uri: http://localhost
fos_js_routing:
    routes_to_expose: [ verification_telephone ]

config/routes/fos_js_routing.yaml:

fos_js_routing:
  resource: "@FOSJsRoutingBundle/Resources/config/routing/routing

routes.yaml:

verification_telephone:
 path: /verification/phone/{extension}
 controller: App\Controller\TelephoneController::Phoneverif1
 options:
     expose: true

and i add these two lines in my twig template

<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

its okey ,

I'm trying to implement my symfony form ,with ajax to verify the existence of data in db and to show alert messages when the form submitted with empty fields . I submit an add action with a function , but its doesn't work the dev console doesn't shows me any ajax request , just im getting an error .. here is my topic about the case : https://stackoverflow.com/questions/65810386/submit-symfony-5-form-with-ajax https://stackoverflow.com/questions/65761177/call-javascript-function-from-twig-symfony-5 so im keep thinking its just a misconfiguration of fos and i can 't find any solution ... thank you for your reply feel free to take a look in my topic..

ednv commented 12 months ago

I had (more or less) the same issue. I added to routes.yaml :


  defaults: { _controller: fos_js_routing.controller::indexAction, _format: 'js' }
  path: /js/routing/{_format}
  requirements:
      _format: 'js|json'```
tobias-93 commented 12 months ago

@ednv that is not needed as long as you import the routing resource FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml. Even though the name suggests it is only for Symfony 4, it works perfectly fine for 5 and 6 (and probably for long after). If you use Symfony Flex this is all done for you so you don't even have to worry about it. The original issue is no longer relevant I would think, so I will close it.