mr-fan Posted August 21, 2015 Share Posted August 21, 2015 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 More sharing options...
mr-fan Posted August 22, 2015 Author Share Posted August 22, 2015 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 More sharing options...
mr-fan Posted August 22, 2015 Author Share Posted August 22, 2015 Ahh seems i've the same problem like here: https://processwire.com/talk/topic/10487-dependencies-for-page-prev-page-next-methods/ Link to comment Share on other sites More sharing options...
mr-fan Posted August 22, 2015 Author Share Posted August 22, 2015 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 More sharing options...
mr-fan Posted August 22, 2015 Author Share Posted August 22, 2015 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 More sharing options...
Soma Posted August 22, 2015 Share Posted August 22, 2015 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. 1 Link to comment Share on other sites More sharing options...
mr-fan Posted August 23, 2015 Author Share Posted August 23, 2015 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 More sharing options...
Mikel Posted August 24, 2015 Share Posted August 24, 2015 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 More sharing options...
mr-fan Posted August 24, 2015 Author Share Posted August 24, 2015 With Soma's workaround or better option on save it works perfect. For the strange behaviour that only prev/next is affected i've created a issue on gh: https://github.com/ryancramerdesign/ProcessWire/issues/1359 regards mr-fan Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 3, 2015 Share Posted September 3, 2015 Alternatively, after save you could do this (for the added lulz, I guess?): $anzeige = $pages->get($anzeige->id); echo $anzeige->next()->id; //1234 Link to comment Share on other sites More sharing options...
mr-fan Posted September 4, 2015 Author Share Posted September 4, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now