Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a fully qualified urlFor() helper #1326

Closed
akrabat opened this issue Jun 28, 2015 · 6 comments
Closed

Need a fully qualified urlFor() helper #1326

akrabat opened this issue Jun 28, 2015 · 6 comments
Labels
Milestone

Comments

@akrabat
Copy link
Member

akrabat commented Jun 28, 2015

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.

@akrabat akrabat added the Slim 3 label Jun 28, 2015
@akrabat akrabat added this to the Version 3.0.0 milestone Jun 28, 2015
@Melbournite
Copy link

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
Copy link
Member Author

akrabat commented Jun 29, 2015

See slimphp/Twig-View#20

@akrabat
Copy link
Member Author

akrabat commented Jun 29, 2015

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
Copy link
Member Author

akrabat commented Jun 30, 2015

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

@calmdev
Copy link

calmdev commented Jun 30, 2015

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
Copy link
Member

This have now been merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants