slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

Need a fully qualified urlFor() helper #1326

Closed akrabat closed 9 years ago

akrabat commented 9 years ago

In the current Slim 3, to create a fully qualified URL for a given route name, you need to do this inside a route callable:

$router = $this->router;
$uri = $request->getUri();

$url = $uri->getScheme() . '://' . $uri->getHost()
        . $uri->getPort() ? ':' . $uri->getPort() : ''
        . rtrim($uri->getBasePath(), '/')
        . $router->pathFor('news-archive', ['year'=>'2015'], ['foo' => 'bar']);

We need a helper method for this.

Melbournite commented 9 years ago

Related question -- Are we going to rename url_for() in Twig-View to match what we named it here? Being I guess path_for() for consistency? Deprecate url_for() and I guess create a uri_for() or similar so that names are aligned with functionality and maintain a level of consistency.

akrabat commented 9 years ago

See https://github.com/slimphp/Twig-View/pull/20

akrabat commented 9 years ago

Based on IRC chat:

Another option would be to add a method to the Request that returns the combination of scheme, domain, port and base path. It could be used something like this:

$url = $app->request->siteUrl($app->router->pathFor('hello'));

or

$url = $app->request->siteUrl() . ltrim($app->router->pathFor('hello'), '/');
akrabat commented 9 years ago

How about something like #1328 to provide an easy way to get the fully qualified URL including the base path?

calmdev commented 9 years ago

This would be nice. I always run into the need for this when sending emails that need to provided a full URI so folks can click to access the application.

silentworks commented 9 years ago

This have now been merged in.