Jump to content

PW 3.0 API Bug?


Jonathan Claeys
 Share

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?

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

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