FOSJsRoutingBundle
FOSJsRoutingBundle copied to clipboard
Dump cant read base url
I place my symfony app under sub path :
myshop.com/nextapp/
if use {{path('product-detail', {id : 1})}} it will generate link : myshop.com/nextapp/product/detail/1
but if I use FOS JsRoutingBundle for my js generate path :
Routing.generate('product-detail', {id : 1}); it will generate link : myshop.com/product/detail/1 without sub path
is there any good way to solve this case, so FOSJsRoutingBundle can read base url?
As specified by @stof in many issues, I try configuring the request context globaly http://symfony.com/doc/current/console/request_context.html#configuring-the-request-context-globally
But it doesn't fix the problem ...
Here is my route (with "/admin" prefix set in routes.yaml file)
admin_images_upload:
path: /image/upload
controller: App\Controller\Admin\ImageController::upload
options:
expose: true
To be correct, generated url will be
http://localhost/blog2/public/admin/image/upload
Without configuring request , Routing.generate('admin_images_upload') gives
http://localhost/admin/image/upload
And after ading this in services.yaml file
parameters:
locale: 'fr'
router.request_context.host: localhost
router.request_context.base_url: blog2/public
Routing.generate('admin_images_upload') gives me that ...
http://localhost/blog2/public/admin/blog2/public/admin/image/upload
Results are the same with a virtual host ...
I use SF 4.0.9 and FosJSRoutingBundle 2.2
Well it's not possible from the console to determine the base url. Therefore there's a flaw by essence in dumping routing data to JSON. One can either set the base url in the parameters.yml and then do the dump, or override the dumped json file (which is a bad idea because it would be overwritten everytime you add routes).
I believe this problem should be documented. @willdurand I might submit a PR for this
when dumping routes in JSON, you need to make sure that your console is configured to be able to generate URLs: https://symfony.com/doc/current/console/request_context.html
Sure ! I believe this is an important information to share in the documentation of this bundle :smile: