The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

How to get the current URL?

Casey McL.'s Avatar

Casey McL.

09 Apr, 2012 07:46 PM

Great framework! How do I get the current URL?

Let's say I'm accessing a route 'login' in my app, which is located at http://example.com/pathtoapp/, and I have URL rewriting turned off. The full URL is: http://example.com/pathtoapp/index.php/login.

Is there a method I can call to get that full URL as a string? I could not find it in the docs.

  1. Support Staff 1 Posted by Josh Lockhart on 09 Apr, 2012 07:47 PM

    Josh Lockhart's Avatar

    Which version are you using?

  2. 2 Posted by Casey McL on 09 Apr, 2012 07:49 PM

    Casey McL's Avatar

    Using Slim v1.5.0.

  3. Support Staff 3 Posted by Josh Lockhart on 09 Apr, 2012 07:53 PM

    Josh Lockhart's Avatar

    You can use the Request object's getRootUri() and getResourceUri() to construct a full absolute path. You'll have to derive the host on your own, likely from the $_SERVER['HTTP_HOST'] variable.

    I encourage you to move to the release-1.6.0 branch (soon to be merged into master); the Request object in that version has been overhauled with many additional helper methods for fetching information about the current URL.

    Hope this helps!
    Josh

  4. 4 Posted by Casey McL. on 09 Apr, 2012 07:57 PM

    Casey McL.'s Avatar

    Sure does. Thanks very much!

  5. Josh Lockhart closed this discussion on 09 Apr, 2012 08:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac