speculatius Posted January 19, 2016 Share Posted January 19, 2016 Hello, I have been playing with PW for last 2 months. So far everything was really intuitive and straightforward. However, I get into some strange behaviour yesterday and I would like to let you know about it. I build website with 2 languages - default and english. All pages exist for default language, but only some of them are active for english. Let's say this is the structure: Home + About (default + english language) + Contact (default language only) Now I execute the following code: $user->language = $languages->get('default'); $children = $homepage->children; As you would expect, variable $children contains pages [about, contact]. Also if I execute... $user->language = $languages->get('english'); $children = $homepage->children; ...variable $children contains pages [about]. But here comes the trick. Let's execute this: $user->language = $languages->get('default'); $defaultChildren = $homepage->children; $user->language = $languages->get('english'); $englishChildren = $homepage->children; You would expect, that $defaultChildren == [about, contact] and $englishChildren == [about]. But that is NOT true. Both of them contain [about, contact]. The problem probably is, that first call to $homepage->children is cached somehow. If you call it second time, language change is ignored and the same output is given again. Workaround for me is to make second call little different, but semanticaly the same. For example: $user->language = $languages->get('default'); $defaultChildren = $homepage->children; $user->language = $languages->get('english'); $englishChildren = $homepage->children('parent=' . $homepage); And that is all Have a nice day. Martin 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 19, 2016 Share Posted January 19, 2016 This seems like a undesirable behaviour, which should be changed in my opinion. Would you please post your findings in an issue at github? You can just summarize the issue and link to here for further explanations. Link to comment Share on other sites More sharing options...
SiNNuT Posted January 19, 2016 Share Posted January 19, 2016 Where does $homepage come from? Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 19, 2016 Share Posted January 19, 2016 Some profiles do have this code in the _init.php $homepage = $pages->get("/"); Link to comment Share on other sites More sharing options...
speculatius Posted January 20, 2016 Author Share Posted January 20, 2016 Thanks for your responses. Respective issue was created: https://github.com/ryancramerdesign/ProcessWire/issues/1622 . Variable $homepage was used only for illustrative purposes. LostKobrakai's definition as $pages->get("/") would fit just right. 2 Link to comment Share on other sites More sharing options...
SiNNuT Posted January 20, 2016 Share Posted January 20, 2016 I see Ryan already pushed a fix on Github ::thumbsup:: 2 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