Jump to content

Weird trouble with $session->redirect


totoff
 Share

Recommended Posts

Hello all,

I was absent for a while from developing - seems I got rusty in the meantime ... Having weird trouble with trying to redirect a page to its first child. I have the following structure:

- /section/ (template A)

-- /child 1/ (template B)

-- /child 2/ (template B)

and so on.

Template A has the following conditional:

if($page->numChildren) $session->redirect($page->child()->url);

However, whenever /section/ is clicked, it redirects to /child 2/ but not to /child 1/. This happens on every section with template A and children.

To make this even more weird, the redirect has worked perfectly fine for weeks and the strange behavior occurred today after editing content in the admin.

Template A sort settings == none

/section/ page sort settings == nothing selected

I've tried selector "sort=sort" but it changes nothing (/child 1/ is the oldest page). I've also tried to set child sort order on /section/ to manual-drag-and-drop. Again without success.

I'm quite helpless with this and would appreciate any help. Thanks.

Link to comment
Share on other sites

Hi LostKobrakai,

thanks for your post.

$page->children without selector echoes the correct order.

$content2 = $pages->get(1015)->children("sort=-sort");

returns /child 2/ as the last item in the list (that is, the oldest page). However, /child 1/ is definitely older as per its created timestamp ...

EDIT: corrected confusion of younger/older

Link to comment
Share on other sites

I don't know exactly, but does sort=sort not sort by the order of pages are in the pagetree? sort=created would sort by creation date. Also there shouldn't be a problem if children() returns the right order as child() internally calls children() and just returns the first page if there are children.

  • Like 1
Link to comment
Share on other sites

I don't know exactly, but does sort=sort not sort by the order of pages are in the pagetree?

Yes, you are right, it does. I was wrong.

Also there shouldn't be a problem if children() returns the right order as child() internally calls children()

I tried

$content2 = $pages->get(1015)->children->first;

and it returns /child 1/ (id 1023). However, the problem remains

if($page->numChildren) $session->redirect($page->child()->url);

still redirects to /child 2/ (id 1024) ...

Link to comment
Share on other sites

Hi Nico,

if($page->numChildren) $session->redirect($page->children->first->url);

works. But I would still like to understand why

$content2 = $pages->get(1015)->children("sort=-sort");

renders child 2 as child 1 while

$content2 = $pages->get(1015)->children("sort=sort");

renders the correct order. I mean, there is something wrong obviously ...

$pages->get(1015)->children->first

is not applicable as 1015 is just one out of many sections sharing the same problem.

Link to comment
Share on other sites

Do you mean sort=-sort is not just reverting the order, but mixing it up?

Yes, exactly.

$content2 = $pages->get(1015)->children("sort=sort");

renders 1023|1024|1031 which is correct

$content2 = $pages->get(1015)->children("sort=-sort");

renders 1031|1023|1024

See what I mean?

Link to comment
Share on other sites

Is it possible that 1023 and 1024 were created at the same moment? Because in that case, sort=sort acts like sort=created|id and sort=-sort would be sort=-created|id, this your real order would be something like (1023, 1024), 1031 and 1031, (1023, 1024).

(This is just a pseudocode, afaik there isn't anything like sort=created|id)

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