Jump to content

How to debug $page->prev - $page->next no output given


mr-fan
 Share

Recommended Posts

So i'm a little confused now.

this $page->prev and next thing i've used several times...but now i'm stucked.

Did some poor debugging like:

echo 	'<p> List: '.$page->siblings().'</p>';
echo 	'<p> Prevout: '.$page->prev.'</p>';
echo 	'<p> Nextout: '.$page->next.'</p>';

result is:

List: 1092|1089|1087|1069
Prevout:
Nextout: 

Setup are normal contentpages (articles) and there are 4 pages...i don't no why $page->prev is empty?

No i'm not at the last or first page...working with 2.6.13 dev

regards mr-fan

Link to comment
Share on other sites

Tested the same setup/site profile in a stable 2.6.1 and $page->prev and $page->next are empty again....

Could this be a strange setting or a bug?

What the heck could supress the prev / next page??

On all normal pages it works only in this article pages i don't get it - is there may a problem within the template settings or the parent page template?

I'm kinda stumped!

Link to comment
Share on other sites

I could track down the issue but i didn't know why this happens...too less skill:

i ripped off all modules, admin.php hooks and content on the specific template and get the problem nailed to this function that output links of some ads so CAN ANYBODY tell me my mistake and WHY this little function clears $page->prev $page->next?

/**
 * Show Ads in several templates
 *
 * $limit - Integer - set the limit of displayed ads ->look at anzeige_anzahl /settings/werbeanzeigen/
 *
 */

function renderAdsystem($limit = 2) {
	//get all ad pages on template choice - unpublished pages are not listed....
	$limit = wire('pages')->get('1073')->anzeige_anzahl;
	$anzeigen = wire('pages')->find("template=part_ad, limit={$limit}, sort=random");
	//render ads and collect them in $all_adds
	$all_ads = "";
	foreach ($anzeigen as $anzeige) {
		$anzeige->of(false);
		$anzeige->anzeige_views += 1;
		$anzeige->save(array("quiet" => true));
		$anzeige->of(true);
		//get the right imagesize
		$anzeige_bild = $anzeige->bild->size(260,120);
		//build ad link
		$all_ads .= '<a href="'.$anzeige->url.'" alt="'.$anzeige->title.'"><img src="'.$anzeige_bild->url.'" alt="'.$anzeige->title.'"></a>';
	}
	return $all_ads;
}

I have to switch the rendering of the ads so it should work!...

best regards mr-fan

Link to comment
Share on other sites

So next step of getting the answer....;)

it seems that if i save the ad view counting i create the problem...but i don't know if this is a maybe a bug?

		$anzeige->of(false);
		$anzeige->anzeige_views += 1;
		$anzeige->save(array("quiet" => true));
		$anzeige->of(true);

If i run without this saving all works the ads are there and the $page->prev $page->next is not empty.....if i save the counterfield...prev and next is empty?

So finally i worked it out - last question stays - Is this a bug or a issue on my code?

Best regards mr-fan

Link to comment
Share on other sites

Try this

$anzeige->save(array("quiet" => true, "uncacheAll" => false));

Any page save clears some cache. I don't know but it was always like this that when you have page saves on front-end templates happening.

That might interferer with some methods that are cached previously. Not sure why prev and next are affected here, could be a bug or a side effect of an optimization for these methods that have some overhead.

You can also call a $pages->uncacheAll(); before your $page->next and it won't work.

  • Like 1
Link to comment
Share on other sites

Thank you Soma for the lession..

works like it should.

So the last question on this is - is it a bug or is it a feature? ;)

But at the end with this option it is solved. But if this behaviour is correct it should documented somewhere? I found the option "quiet => true" in the forum but "uncacheAll" not until now.

Thank you again for this insight.

Regards mr-fan

Link to comment
Share on other sites

So the last question on this is - is it a bug or is it a feature? ;)

IMHO its a bug. We decided to drop everything relying on the prev() and next() methods until this gets fixed. If PW is able to return the sibling PageArray, it should to be able to traverse it, shouldn't it?

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for your contribution on this topic.

but $anzeige (ad) should only be saved on this pages and on all for example "blogpages" that have the function renderAdsystem() the $page->prev and $page->next is empty..... $page->siblings works the most $page->something that i've tested works...but next/prev don't...

so this seems to be a bug or a feature and you need the workaround/option from soma that works so far...

regards mr-fan

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...