Noel Boss Posted October 30, 2017 Share Posted October 30, 2017 Maybe I'm missing something here, but I'm haveing a hard time to get absolute urls if PW is installed in a subdirectory thought the API... I need an absolute URL for the backend (as a redirect url of Oauth provider). To build the url i would normaly use url()->root.url()->admin – but this results in the install-path beeing present twice; domain.com/path/ + path/admin/ In order to not use $_SERVER['HTTP_HOST'] I fetch the admin page from pages – but this is also not to easy since I need to remove the root folder from path as well. My current solution is somewhat complicated: $backendUrl = pages()->get('path="'.str_replace(urls()->root, '', urls()->admin).'", include=all')->httpUrl; The above code seems to be the savest way to get the absolute url to the backend using pure PW API, am I right? It would be great if one could fetch absolute urls with something like this $backendUrl = urls()->admin->httpUrl // or $backendUrl = httpUrls()->admin SOLVED: Thank you @adrian – of course this HAD to be simpler: urls()->httpAdmin; Link to comment Share on other sites More sharing options...
Robin S Posted October 30, 2017 Share Posted October 30, 2017 The admin page always has the ID of 2 (as far as I know). So you can get the httpUrl with: $pages(2)->httpUrl() Link to comment Share on other sites More sharing options...
kongondo Posted October 30, 2017 Share Posted October 30, 2017 20 minutes ago, Robin S said: The admin page always has the ID of 2 True.. Maybe better to get it like this...(in case down the road someone wonders what the 2 is all about, etc).. $pages($config->adminRootPageID)->httpUrl(); 2 Link to comment Share on other sites More sharing options...
fbg13 Posted October 30, 2017 Share Posted October 30, 2017 Have you tried $config->urls->httpAdmin ? 4 Link to comment Share on other sites More sharing options...
adrian Posted October 30, 2017 Share Posted October 30, 2017 The "http" may be optionally prepended to any property accessed from $config->urls (including those you add yourself). https://github.com/processwire/processwire/blob/57b297fd1d828961b20ef29782012f75957d6886/wire/core/Paths.php#L49 4 Link to comment Share on other sites More sharing options...
Noel Boss Posted October 31, 2017 Author Share Posted October 31, 2017 Hahaha, fool I was, thinking PW not already soled it has! Once more, what a great community, THANK YOU! API Cheatsheet would trueöy be great with these tibits... So the solution is this: urls()->httpAdmin; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now