noelboss

[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 Robin S
      An experimental module for adding images to a field via pasting one or more URLs.
      Add Image URLs
      Allows images to be added to an images field by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image fields. Use the button to show a textarea where image URLs may be pasted, one per line. Images are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
    • By thomasaull
      I recently started to build Vue SPAs with ProcessWire as the backend, connected with a REST API. Thanks to code and the help of @LostKobrakai (How to use FastRoute with ProcessWire) and @clsource (REST-Helper) I got it up and running pretty quickly and now have put all of it in a site profile for others to use. It includes the REST API with routing for different endpoints, JWT Auth and a simple Vue SPA which shows the process of logging in a user (nevertheless, you don't have to use the Vue part, the API will work on it's own).
      Check it out here: https://github.com/thomasaull/RestApiProfile
      I'm pretty sure, it's not the perfect or most sophisticsted solution, but it gets the job done for me…
      Feedback or Improvements are very welcome
    • By cosmicsafari
      Hi all,
      Just wondering if its possible to just add some basic output to my modules config page.
      I was wanting to output a bulleted list of some information which I will be pulling from a third party.
      Retrieving the data is fine i'm just not sure how to output it to the config page?
      From what I can see in the link below, it only seems like you can append form items to the page.
      https://processwire.com/blog/posts/new-module-configuration-options/
    • By carrdesigns
      In the admin, I am trying to access data from a page that contains an inputfieldand autofill that data into the modal edit window for a new entry.
      For instance, I have a template which contains a PageTable field. When I add a new entry to the PageTable, I want to capture the ID from the originating admin page and add it to a field in the edit modal as a way of linking the new entry back to the originating page. The new PageTable entries are NOT children of the originating page, and cannot be for structural reasons. I have attached an image which I hope will help to clarify the basic result I want to achieve.
      Is there a practical means of accomplishing this? I've been able to achieve something similar with the ConnectPageFields module, but it does not work with PageTable fields. Any input would be much appreciated.

    • By Vinnie
      Hi all, Im trying to fill an options field in all the children of the parent page, after I save it. 
      the options field is configured as multiple select checkboxes. here's the code i have so far:
      $this->addHookAfter('Pages::saved', function($event) { $page = $event->arguments[0]; //set the page if($page->template == 'sport-verenigingen-overzicht') { //get the subcategories from the parent textarea, split on newline $subcats = preg_split('/[\n\r]+/', $page->subcats); //(also tried without imploding and adding the array, also doesnt work) $subcats = implode("|",$subcats); //get the children $children = $page->children(); foreach ($children as $child) { //set the options(sport_categorie is the options field) $child->sport_categorie = $subcats; $child->save('sport_categorie'); } //if i use a normal textfield instead of an optionsfield, //all the children have the correct data e.g: test1|test2|test3 //how to get the values into the options field?? } }); Hope you guys can help! Keep up the good work, I'm loving what you're doing with PW!!