More uses for public_path in Symfony
I’ve already mentioned one use of public_path(), which is to leave as much HTML as possible in the templates, so that designers have an easy time working with them.
This conversation was related, and caught my interest.
Mo Mughrabi wrote:
Generate absolute URL for upload directory
I was trying to generate an absolute URL inside my form classes using sfContext::getInstance()->getController()->genUrl(); but apparently genUrl only can be used when supplied a route or module/action but i cannot get it to return the absolute path of my uploads folder. Any idea how can i do that?
Eno responded:
We never found a good solution for this (we run across a cluster where we need absolute and cross-domain links). Now we are using the sfDomainRoutePlugin to give us this functionality in url_for() and link_to().
And then Mo Mughrabi said:
I found a way which helped me return the absolute url for any location i
need through the public_path helper.First i had to include the helper through the getConfigurations
sfContext::getInstance()->getConfiguration()->loadHelpers(array(’Url’));
and then just use the public_path(’uploads/file.jpg’);