MarcC Posted October 10, 2012 Share Posted October 10, 2012 I ran into something crazy today. It seems like so fundamental of a bug or design issue that surely the root of the problem has to be some crazy server configuration issue on my webhost's end, but even if this is the case, Ryan and other PW devs should know about it. Here is the simple test-case. My site has 4 pages below the root. Their names are about-us, member-info, articles, and site-map. Of these, about-us, member-info, and articles have subpages and can thus be considered "categories." When I'm on the homepage, (that is, $page is '/'), if I do foreach ($page->children() as $child) { echo "{$child->name},"; } I get what you'd expect: about-us,member-info,articles,site-map, OK, now navigate to a "category root" (2nd-level page, doesn't matter which one, I tested them all). Let's say member-info. Let's get the same list as before: foreach ($pages->get('/')->children() as $child) { echo "{$child->name},"; } I again get what you'd expect: about-us,member-info,articles,site-map, Now the rub: navigate to a category child (3rd level page). Let's say /member-info/foobar/ . Let's attempt the same loop as above: foreach ($pages->get('/')->children() as $child) { echo "{$child->name},"; } The result? about-us,home,articles,site-map, What? "home"? Sure enough: echo $page->url; // Prints http://mysite.com/home/foobar/ echo $page->parent->name; // Prints home echo $page->parent->title; // Prints Member Info [like it should] echo $pages->get($page->parent->id)->title; // Also Member Info [like it should] echo $pages->get("/{$page->parent->name}/)->id; // 0, because there is no page named "/home/" So yeah. Basically most properties of the parent page seem to be correct, except name and things that involve name (like url). I have no clue why name is getting changed to "home". The siblings of the page in question are fine. Anyway, thought you should know that it's happening. Any ideas to test are appreciated! This is the problem behind my issue with Soma's module. This client is on a Pair Networks shared server. Link to comment Share on other sites More sharing options...
nik Posted October 10, 2012 Share Posted October 10, 2012 You wouldn't happen to have something like this executed on those 3rd level pages before the foreach? $page->parent->name = 'home'; After that line everything works exactly the way you described. Don't know why you'd do that on purpose, but for example a missing second equals sign in an if statement would explain this. 2 Link to comment Share on other sites More sharing options...
MarcC Posted October 10, 2012 Author Share Posted October 10, 2012 if ($page->parent->name = 'home') { ... Doh. Thanks Nik, mysterious API issue solved, I think. Link to comment Share on other sites More sharing options...
Soma Posted October 10, 2012 Share Posted October 10, 2012 Glad you found out the mystery. Well that's why we do: if("home" == $page->parent->name) Because like this if you miss one "=" it will throw an error. 4 Link to comment Share on other sites More sharing options...
MarcC Posted October 10, 2012 Author Share Posted October 10, 2012 Well that's why we do: Thanks, Soma. I had even read about that technique about a year ago, but never got around to using it. So...now I will. Ha ha 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