Jump to content

API Variables with "Include & Bootstrap"


SwimToWin
 Share

Recommended Posts

I am using ProcessWire as the back-end to manage contents on multiple sites (I call them "sub-domains"). I use ProcessWire as an editing system and database only. The ProcessWire templating system is not in use. I want to use ProcessWire's API and in particular the Include & Bootstrap method to output contents -- pretty much in the same way you do, if contents is stored in a MySQL database and output in PHP files that use PDO to load data.

The issue is that I cannot get ProcessWire to fully work on each of the "sub-domains".

https://processwire.com/api/include/ says:

 

> You can do anything with ProcessWire's API that you can do from a template,
> so all of this still applies, as does everything in the developer API.

How can I get access to variables such as $input when using Include & Bootstrap?

I tried these:

$wire->pages->get("/foo/bar/");
echo "Segment1: " . $wire->input->urlSegment1; # Returns null

$wire->pages->get("/foo/bar/");
echo "Segment1: " . $wire->input()->urlSegment1; # Internal Server Error

$p = $wire->pages->get("/foo/bar/");
echo "Segment1: " . $p->input->urlSegment1; # Returns null

$p = $wire->pages->get("/foo/bar/");
echo "Segment1: " . $p->input()->urlSegment1; # Returns null

@ryan Can the API Variables documentation be updated with a section / an example that explain how to use "Include & Bootstrap" for each variable (since this is a really strong feature in ProcessWire)?

  • $page
  • $pages - Example: $homepage = $wire->pages->get("/");
  • $input
  • $sanitizer
  • $session
  • $fields
  • $user
  • $log
  • $templates
  • $config
Edited by SwimToWin
Background info added
Link to comment
Share on other sites

4 hours ago, SwimToWin said:

How can I get access to variables

Hi,

https://processwire.com/api/include/

These two are equivalent, so what syntax you prefer to use is up to you:

$mypage = $wire->pages->get("/about/contact/");
$mypage = wire('pages')->get("/about/contact/");

wire('pages') As far as I know, only this should work, so they are not really "equivalent" in this context. See for example: https://processwire.com/talk/topic/13977-custom-php-code-selector/?tab=comments#comment-125688

Am I mistaken?

 

Link to comment
Share on other sites

If you are bootstrapping I am guessing this is an ajax call, or a site that is trying access PW data but without using PW template files?

In this case, $input->urlSegments won't work, because it's not a PW template file.

But in general, you can use any PW variable in a bootstrapped scenario normally, eg $page, $fields, $session - no need for $wire or wire()

  • Like 2
Link to comment
Share on other sites

5 minutes ago, adrian said:

If you are bootstrapping I am guessing this is an ajax call, or a site that is trying access PW data but without using PW template files?

In this case, $input->urlSegments won't work, because it's not a PW template file.

But in general, you can use any PW variable in a bootstrapped scenario normally, eg $page, $fields, $session - no need for $wire or wire()

Thanks for clarifying!

Link to comment
Share on other sites

Background info: I am using ProcessWire as the back-end to manage contents on multiple sites. I use ProcessWire as an editing system and database only. The ProcessWire templating system is not in use.

I will describe the setup in a separate topic - it's cool! ;-)

Link to comment
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
 Share

×
×
  • Create New...