Mikel Posted July 23, 2015 Share Posted July 23, 2015 While building our recent project I discovered that I could not adress the siblings of a page with the mentioned methods. Neither do the methods getNext() or getPrev() work. Are there some hidden dependencies I am not aware of? Did not find anything in the docs... To be precise: $g = $pages->find("template=glossary_detail"); $prev = "<a href='{$page->prev($g)->url}'>prev</a> "; $next = "<a href='{$page->next($g)->url}'>next</a> "; Should work, shouldn't it? Link to comment Share on other sites More sharing options...
tpr Posted July 23, 2015 Share Posted July 23, 2015 Have you tried adding any kind of "sort" to your query? ($g) Link to comment Share on other sites More sharing options...
Pete Posted July 23, 2015 Share Posted July 23, 2015 $g is an array of pages in your example that doesn't seem related to a particular page, so how does it know what next and prev are? Next and prev usually relate to the page being viewed, so $page->next() and $page->prev() should be all you need. 1 Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 Yes, just added sort=title to the selector, but the method still returns NULL. The funny thing is, the same code works on all other projects so far. Thats why I am wondering about dependencies ... Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 $g is an array of pages in your example that doesn't seem related to a particular page, so how does it know what next and prev are? Next and prev usually relate to the page being viewed, so $page->next() and $page->prev() should be all you need. Hi, Pete, I tried your code right after this: $prev = ($page->prev->id) ? '<a href="'.$page->prev->url.'">'.$page->prev->title.'</a>' : ''; $next = ($page->next->id) ? '<a href="'.$page->next->url.'">'.$page->next->title.'</a>' : ''; Unfortunately neither is working... Link to comment Share on other sites More sharing options...
diogo Posted July 23, 2015 Share Posted July 23, 2015 Does it work if you do this instead? $prev = "<a href='" . $page->prev($g)->url . "'>prev</a> "; Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 Does it work if you do this instead? $prev = "<a href='" . $page->prev($g)->url . "'>prev</a> "; Unfortunately not :-( But, as I stated before, the methods work fine in other projects, so I want to find the (to me) hidden dependency of these methods. When I output the pageArray $g everything looks fine... Link to comment Share on other sites More sharing options...
diogo Posted July 23, 2015 Share Posted July 23, 2015 What do you get with: print_r($page->next($g)) ? Link to comment Share on other sites More sharing options...
Soma Posted July 23, 2015 Share Posted July 23, 2015 It's all correct and works. So what is different to your other projects? Are pages published? Are they viewable? Is the page really in the PageArray, but when $page->next doesn't even work you seem to have a problem somewhere. No idea sorry. Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 What do you get with: print_r($page->next($g)) ? I get this: NullPage Object ( [template:protected] => [templatePrevious:Page:private] => [parent:protected] => [parentPrevious:Page:private] => [namePrevious:Page:private] => [statusPrevious:Page:private] => [output:Page:private] => [filesManager:Page:private] => [fieldDataQueue:protected] => Array ( ) [isNew:protected] => 1 [isLoaded:protected] => 1 [outputFormatting:protected] => [instanceID:protected] => 0 [pageNum:protected] => 1 [config:protected] => [quietMode:protected] => [createdUser:protected] => [modifiedUser:protected] => [settings:protected] => Array ( [id] => 0 [name] => [status] => 1 [numChildren] => 0 [sort] => -1 [sortfield] => sort [modified_users_id] => 0 [created_users_id] => 0 [created] => 0 [modified] => 0 ) [data:protected] => Array ( ) [useFuel:protected] => [className:Wire:private] => [classNameOptions:Wire:private] => Array ( ) [localHooks:protected] => Array ( ) [trackChanges:Wire:private] => 0 [changes:Wire:private] => Array ( ) [_notices:protected] => Array ( [errors] => [warnings] => [messages] => ) ) Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 It's all correct and works. So what is different to your other projects? Are pages published? Are they viewable? Is the page really in the PageArray, but when $page->next doesn't even work you seem to have a problem somewhere. No idea sorry. Hi, Soma, thats what I'm trying to find out since a couple of hours... pages are published - check pages are viewable - check page is in the pageArray because print($g->each('<p>{title}</p>')); generates the correct output of all pages - check Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 Hello everybody, I finally made it up: The project, still in development, is using Adrians nice module "Protected Mode". This module, if set to protected mode, seems to prevent the next() and prev() methods from working correct. problem solved. PS: After going through the "Protected Mode" module I wonder HOW this module can interfere with the next() and pre() methods... PPS: Now it gets really interesting: IT IS NOT "Protected Mode" module causing the next() & prev() methods to return NULL || nullPage object. the dependency I detected meanwhile is if the current user is logged in or not: anonymous user (aka "guest") --> everything works fine logged in user --> methods return NULL I will keep working on this one... 1 Link to comment Share on other sites More sharing options...
adrian Posted July 23, 2015 Share Posted July 23, 2015 @Mikel and everyone else, Sorry for the hassles - this has obviously been a pain for you and taken up other folk's time as well. I am trying to duplicate here, but can't and also can't figure out how it could be an issue - if you are logged in, the first line inside the module's init() returns before any it does anything else. I'd love to be able to see a test installation where the problem is happening? Any chance you might be able to set up something on lightning.pw or elsewhere? Link to comment Share on other sites More sharing options...
diogo Posted July 23, 2015 Share Posted July 23, 2015 Adrian, read Mikel's correction above. Mikel, next time you want to say something this important, do it in a new post so people know about the change 1 Link to comment Share on other sites More sharing options...
Mikel Posted July 23, 2015 Author Share Posted July 23, 2015 @Mikel and everyone else, Sorry for the hassles - this has obviously been a pain for you and taken up other folk's time as well. I am trying to duplicate here, but can't and also can't figure out how it could be an issue - if you are logged in, the first line inside the module's init() returns before any it does anything else. I'd love to be able to see a test installation where the problem is happening? Any chance you might be able to set up something on lightning.pw or elsewhere? Hi, Adrian, sorry for this! Next time I will do this in a new post. mea maxima culpa! 1 Link to comment Share on other sites More sharing options...
mr-fan Posted August 22, 2015 Share Posted August 22, 2015 @Mikel seems i've in the same trouble like you - did you get the problem solved? Link to comment Share on other sites More sharing options...
mr-fan Posted August 23, 2015 Share Posted August 23, 2015 Crosslink with solution in other threat.....just for connecting things right. https://processwire.com/talk/topic/10731-how-to-debug-page-prev-page-next-no-output-given/#entry101066 regards mr-fan Link to comment Share on other sites More sharing options...
Mikel Posted August 24, 2015 Author Share Posted August 24, 2015 @Mikel seems i've in the same trouble like you - did you get the problem solved? No, 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, should't it? Link to comment Share on other sites More sharing options...
Mikel Posted March 4, 2016 Author Share Posted March 4, 2016 After upgrading the ProcessWire installation to 2.7.2 the methods next() and prev() work like they should. 1 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