processwire / processwire-requests

ProcessWire feature requests.
40 stars 0 forks source link

Please add $config->path($url) and $config->url($path) to API #326

Open BernhardBaumrock opened 5 years ago

BernhardBaumrock commented 5 years ago

Short description of the issue

I find myself very often converting paths to urls and vice versa. For example today I had to deal with it when using MPDF library and file field items.

Expected behavior

It would be great to have an easy and fool proof solution to convert relative urls to paths and paths to relative urls.

Actual behavior

At the moment we need to do complicated string concatenations that are even error prone (for example when one does not think of different directory separators on different platforms or installations in subfolders). See my related PR here: https://github.com/processwire/processwire/pull/143

Examples of possible API implementation

$url = $pages->get(123)->mypdf->url;
// eg /site/assets/files/123/myfile.pdf

$path = $config->path($url);
// eg /var/www/mysite/site/assets/files/123/myfile.pdf

$url = $config->url($path);
// again /site/assets...
teppokoivula commented 5 years ago

Note: this doesn't seem like an issue, so seems like a better fit for the processwire-requests repository.

BernhardBaumrock commented 5 years ago

True, thx @teppokoivula and @netcarver 👍

BernhardBaumrock commented 5 years ago

I think $config->path() and $config->url() would even be a better choice (without the S) - edited the headline

BernhardBaumrock commented 2 years ago

Hey @ryancramerdesign once more this is really painful for me:

Im returning preview images (JPG) for files in a files field (PDF), where $preview holds the file PATH to the JPG. I need the path to check if the file exists, but I need the URL for the <img> tag to define the src attribute:

image

Having a $config->url($path) API method would make this a lot easier and straightforward:

image

BernhardBaumrock commented 2 years ago

I've just added a PR for this request: https://github.com/processwire/processwire/pull/210