Jump to content

Dependencies for $page->prev & $page->next methods?


Mikel
 Share

Recommended Posts

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

$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.

  • Like 1
Link to comment
Share on other sites

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

$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

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

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

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

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

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...  :huh:

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...

  • Like 1
Link to comment
Share on other sites

@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

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 ;)

  • Like 1
Link to comment
Share on other sites

@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!  :blush:

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

@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

  • 6 months later...

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...