Jonathan Claeys

PW 3.0 API Bug?

Recommended Posts

I just noticed when I try to do this in the ready.php that it can not retrieve the page. This works perfectly in the init. But since I need my languages I'm forced placing it in the ready. I'm just trying to get the child from a page.


Var_dumping that gives me a Nullpage. (and yes the name is correct since it does work in init.php but doesn't in ready.php) So I have no idea what I'm doing wrong, I was guessing maybe it's a bug?

Share this post

Link to post
Share on other sites

I believe your guess is wrong, :)

Can you please paste in the original code you use in your ready.php, incl. the scope, (your hook method you use).

Please use the <> button of the forums editor, it opens a modal that let you paste in your code and let you select the code type (php, html, css, js).

This is of great help for readability.

Share this post

Link to post
Share on other sites

Ok this is what I used in the init.php:

	//header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));

	 * Rootpages
	$root = $pages->get(1);
	$rootPages = $root->children()->prepend($root);
	$this->wire('rootPages', $rootPages);

	 * Settings
	$fields = array();

	foreach($pages->get("name=settings")->child as $key => $f){
		$fields[$key] = $f;

	$fields = (object) $fields;

	$this->wire('settings', $fields);

	 * Translations
	$translations = array();

	foreach($pages->get("name=settings")->child->translations as $key => $t){
		$translations[$t->key] = $t->string;

	$translations = (object) $translations;

	$this->wire('t', $translations);

I get this error: Invalid argument supplied for foreach(), the problem is that $pages->get("name=settings") returns a page, but when I add ->child it's a nullpage. While it does have a child, and just works correct in the init.php but not in the ready.php.

I just make some wire objects to use myself along the whole website. For example for some settings like e-mail, phone, ... I make them accessible as: $settings->phone or $t->some_translation_key.

  • Like 1

Share this post

Link to post
Share on other sites

Ok problem solved, I've found the issue. Apparently pages that have a parent or ancestor that is hidden also require you to use ("include=all") as selector, even if the page itself is not hidden. I was searching for hours on that. :P

Thanks for your help anyway! 

  • Like 3

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
      Does anyone know how to change the title of a select options to lower case? Right now, I have 3 options: "Management, Editor, Guest" (titles are uppercase in the backend), and I would like to change them to lower case in my template as I am adding them as a class name to span tags, ie "<span class="management"></span>".
      I will note, that I am using $level->title (the options) in a nested foreach loop, if this changes anything. Also, I thought I could use strtolower(), but it is just being "echo'd" in the source code.
    • By cst989
      I have a file I want to access with ajax:
      The purpose of this file is to iterate through a repeater, and get the image from each entry.
      The number of images in the image field is set to 1, and just for good measure, to return a single image.
      And my code:
      // site/ajax/processImage.ajax.php?group=1206 require_once($_SERVER['DOCUMENT_ROOT'].'/index.php'); $resourceGroup = (int) $_REQUEST['group']; // get the Repeater field $resources = $pages->get($resourceGroup)->resources; foreach ($resources as $resource) { echo $resource->title; // Works as expected echo $resource->image->url; // /site/assets/files/1259/ echo $resource->image; // filename.jpg echo $resource->image->description; // nothing } See comments above for what is output, why isn't URL giving me a full URL, and no description is available?
      If I try to access $image->size() I get the following fatal error:
      Error: Uncaught exception 'ProcessWire\WireException' with message 'Method Pageimages::size does not exist or is not callable in this context' in F:\sites\<sitename>\wire\core\Wire.php:519
    • By Mijo
      Hello all, I'm playing with Wordpress API and I trying to create pages in Processwire from WP API, did anybody do something like that (or any other api)? What is the best approach for creating pages via external API, any advice, examples would be awesome, thank you all
    • By modifiedcontent
      I have one central website, with membership registration and content etc., and then several related websites with their own URL/domains, each on Processwire, all on the same server.
      I would like to access the database of the central website from the sister websites. How would I do that?
      You can't bootstrap one PW installation into another. You can include template parts from one in the other by just using the server path, but whatever you try to get/post just comes/goes to the database of the site you are on.
      Could you switch databases by including the config.php from another PW installation somewhere?
      What is the correct, secure way to do this?
    • By celfred
      I have a feeling I'm missing an easy thing here (again...). If I trash a page from API with :
      Is there a simple way to restore it if needed ? I can do it in back-end, but I'd like to do it through API with something like
       but this doesn't exit  
      So if you can give me a little help on that, I'd appreciate. Thanks in advance !