How to get the full url for an asset in Controller?

前端 未结 15 2155
悲&欢浪女
悲&欢浪女 2020-12-12 16:13

I need to generate some JSON content in controller and I need to get the full URL to an uploaded image situated here : /web/uploads/myimage.jpg.

How can

15条回答
  •  甜味超标
    2020-12-12 16:58

    As of Symfony 2.1 you can use:

    $request->getSchemeAndHttpHost().'/uploads/myimage.jpg';
    

    Note: This solution has the advantage to work in both DEV and PROD environments.

提交回复
热议问题