Noel Boss

[SOLVED] Extend API with httpUrl()

Recommended Posts

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;

 

Share this post


Link to post
Share on other sites

The admin page always has the ID of 2 (as far as I know). So you can get the httpUrl with:

$pages(2)->httpUrl()

 

Share this post


Link to post
Share on other sites
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();

 

  • Like 2

Share this post


Link to post
Share on other sites

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;

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      So I have a form, once completed, will create new pages. All in all, this is eazy-peezy for me now. I guess I need a bit of guidance on how to actually structure the rest of my code.  I thought I could just write a function (_func.php) and pass the fields to the function and let it do its' thing. However, I am kinda hitting a road block when I do it this way. 
      I currently am passing first name, last name, city, state (options field), and making pages based on the first/last names. I guess where I run into some issues is I am trying to check to see if the "page" already exists, and if it does, throw out an error:
      In the home template:
      if(isset( $_POST['submit'])) { $firstName =Trim (stripslashes($_POST['firstname'])); $lastName = Trim(stripslashes($_POST['lastname'])); $fullName = $firstName . $lastName; $city = Trim(stripslashes($_POST['city'])); $state = Trim(stripslashes($_POST['state'])); $lowerCaseName = strtolower($fullName); $people = $pages->find("template=person"); foreach ($people as $person) { $checkFirstName = $person->first_name; $checkLastName = $person->last_name; $checkFullName = $checkFirstName . $checkLastName; if ($checkFullName === $lowerCaseName) { echo "<p>" . "This person has already created a page. Please choose a different name." . "</p>"; } else { echo "hey"; processNewPerson(need_to_pass_person_details_to_function); } } // end foreach In _func.php:
      function processNewPerson($list) { $u = new Page(); $u->template = "person"; $u->parent = wire('pages')->get("/people/"); $u->title = ; $u->first_name = ; $u->last_name = ; $u->state = ; $u->city = ; $u->save(); $u->setOutputFormatting(false); } I am a little unsure of how to actually pass all the information to the template, as well as if this is even the best approach to do this. Would it make more sense to do this in a class, or keep it the way it is?
    • By benbyf
      I always seem to get this warning on every new install of PW on my Ubuntu 14 box with Digital Ocean. The servers are usually based in the UK and I was wondering if I should be adding something other than the below in the config? Is there a UK based locale code? Quick Google didnt come up with much.
      Warning: your server locale is undefined and may cause issues. Please add this to /site/config.php file (adjust “en_US.UTF-8” as needed): setlocale(LC_ALL,'en_US.UTF-8');
      Added to the config file:
      setlocale(LC_ALL,'en_US.UTF-8');  
    • By louisstephens
      I have done a bit of searching, but I can not seem to find an actual answer. I have a list of services as child pages under "Services". I can output the services just fine, but I cant wrap my head around how to group them "alphabetically" like:
      Services A - Service "A" 1 - Service "A" 2 - Service "A" 3 B - Service "B" 1 - Service "B" 2 - Service "B" 3 C - Service "C" 1 - Service "C" 2 - Service "C" 3 Has anyone achieved this type of functionality before?
    • By rushy
      I'm trying to migrate a PW site on my local dev server to a shared hosted server and have used the ProcessExportProfile module to export a profile as a zip file. So far so good. I then deploy new install of PW on the server by unzipping the PW installation files but I do not run the install until I have replaced the various site profiles with the files from the exported profile. So basically:
      In the PW install files I delete all the site-* folders except site-default. This one I overwrite with  the export profile folders so it contains my assets, install, modules and templates folders together with the exported config.php
      I then run the install in the browser in the normal way and it starts the installation and I can see my website profile in the list and I select it. It proceeds as normal and gets to setting up the database. I provide the db info. as usual and it proceeds as far the info. below and 'hangs' at this point , it never goes on to setup the PW login admin. and complete the install I am left at that screen.  
      If I relaunch the browser at the site it all seems to work! BUT I have no admin login to PW so cannot get into the backend. 
      I have basically followed the Installation, Moving and Troubleshooting guide by Joss Sanglier: http://processwire.com/docs/tutorials/installation-moving-and-troubleshooting/page4
      Any idea where I could check for an error log or some help as I am at a loss as to the problem. 
      Many thanks. Paul
      ProcessWire 3.x Installer
       Test Database and Save Configuration
       Database connection successful to pinpoin1_master
       Saved configuration to ./site/config.php
       Profile Import
       Imported database file: ./wire/core/install.sql
       Imported database file: ./site/install/install.sql
    • By quickjeff
      Hey guys, 
      Looking for another dev to help on multiple processwire projects as well as some other PHP apps. 
      First project is a directory style site with lots of components to come, including stripe implementation  and other fun stuff.
      Need someone ASAP to help out. 
       
      Thanks.