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.

$pages->get("name=settings")->child();

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
horst    3,961

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:

<?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 celfred
      Hello,
      Just a simple (I think) question which is in the title of my post.
      Roughly speaking : here's my code (made-up because my real function is so long... I don't want to post it all here )

      function updateScore($player, $task, $real = true) { [...] $player->score = $player->score+$task->score; if ($task->name == 'new-equipment') {   $new-eq = $pages->get("name=sword");   $player->equipment->add($new-eq); } if ($real == true) {   $player->save(); } }
      Everything works fine when I call updateScore($player, $task, true), but if I call updateScore($player, $task, false), scores are untouched, but the equipment gets added !
      It used to work fine on PW2.7 but my update to PW 3.0.62 seems to have broken this... Is there a simple explanation ? I keep reading my code over and over and this is driving me crazy...
      Thanks !
    • By zaib
      I've a page "blog" which have child pages (blog posts). Right now I've 11 pages (blog posts) and I'm fetching all the posts in my "blog" pages which displaying fine, Issue is only 10 results are showing this is how I'm fetching
      $entries = $pages->find("template=blog-entry"); foreach($entries as $entry){ <a href='{$entry->url}'>$entry->title</a> }  
    • By darrenc
      What I did
      edit the default 'body' field (textarea, ckeditor) field > body > input: "enable ACF" checked "yes" by default field > body > input: "extra allowed content" ... The instructions indicate "Example: img[alt,!src,width,height]" in order to enable a tag with attributes you want to allow through the filtering.
      a[class] I wrote the above expecting that now i would be able to class my a tags in the editor, maybe make one a "button" style or whatever. However, this doesn't actually work as it seems Extra Allowed Content doesn't actually do what it indicates.
      I've tried a dozen different variations and after googling here and seeing some responses in other threads, I think this should be addressed. The box is a nice way to enable a few attributes the user might want to allow for clients or themselves, I don't see why one would require making a module or going above and beyond the tools and text areas already provided in order to simply allow a few attributes.  I could turn ACF Off entirely, but that doesn't really address the problem: I want to filter the input for clients but still configure some tweaks that I deem would enhance and not break the site.
      Simply: it's there, it's nice to have, should work right, but it doesn't seem to. Help?
       
       
    • By pppws
      hey there,
      i'm quite new to processwire but i'm having a great experience using it!
      right now i hit a point where i can't help myself out with google/searchfunction.
       
      to sketch the basic functions of my page:
      visitors can enter their e-mail in a form. when doing this pw creates a new page, using the e-mail's md5 hash as a name. the url of the page is sent to the user. the user now can edit the newly created page and can fill out fields like: name and year of birth (thanks to the docs those two already work like a charm!) but there are other fields like "residencies", which are repeaterfields containing three fields: city (text), country (text), current (checkbox). at my current version i can populate a new repeater field easily by using this code:
      $location = $page->locations->getNew(); $location->location = Munich; $location->country = Germany; $location->current = 1; $location->save(); $page->locations->add($location); now i want to populate the new reapter fields from input fields (using the simple form api). which leads me to my questions:
       
      1. can i somehow group/merge input fields to one "repeater input fields" right now i have:
      // create a text input -> locations $field = $modules->get("InputfieldText"); $field->label = __('City'); $field->attr('id+name','location'); $field->required = 1; $form->append($field); // append the field to the form // create a text input -> country $field = $modules->get("InputfieldText"); $field->label = __('Country'); $field->attr('id+name','country'); $field->required = 1; $form->append($field); // append the field to the form // create a checkbox -> locations $field = $this->modules->get('InputfieldCheckbox'); $field->attr('name', 'location_current'); $field->attr('autocheck', 1); $field->attr('uncheckedValue', 0); $field->attr('checkedValue', 1); $field->attr('value', $this->fname); $form->append($field); // append the field to the form 2. my desired layout for the form looks like this:

      by hitting the + button a new line shows. i'm wondering what's the best practice here. can is somehow use the above mentioned code itself as a repeater, or do i have to create several (uniqe) input fields in advance and hide them afterwards (javascript)?
       
      any help is appreciated!
      thanks!
    • By alexcapes
      Hi,
      I've been invited by Apple to use their 'News' service for a publication in the UK. https://www.apple.com/uk/news/
      A number of CMSs already have plugins to publish content via the API, however Processwire is not one (yet!)
      https://newsresources.apple.com/en/faq/66346243
      It's slightly beyond my technical abilities but would be very interested in anyone that is willing to look at developing a Processwire Module.
      (for reference here is the Apple News API documentation)
      Update: Chapter Three have created a PHP Apple News library here https://github.com/chapter-three/AppleNewsAPI