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

前端 未结 15 2140
悲&欢浪女
悲&欢浪女 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:59

    You can use this in Controller:

    $this->getRequest()->getUriForPath('/uploads/myimage.jpg');
    

    EDIT : This method also includes the app.php and app_dev.php to the url. Meaning this will only work in production when url-rewriting is enabled!

提交回复
热议问题