Jump to content

speculatius

Members
  • Posts

    4
  • Joined

  • Last visited

speculatius's Achievements

Newbie

Newbie (2/6)

4

Reputation

  1. Ok. One solution is to extend ProcessWire\Wire: class Utils extends \ProcessWire\Wire { public function func() { $this->_('car'); } }
  2. Hello, I face interesting issue in PW v3. I have utility class, which is loaded from template. Class is put in namespace due to some naming collisions. But it is impossible now to use translatable strings in it. <?php namespace site\util; class Utils { public function func() { __('car'); // Error - function site\util\__ does not exist. $this->__('car'); // Error - method Utils::__ does not exist. \ProcessWire\__('car'); // Code runs, but PW does not recognize translatable string in admin area. } } I guess that this will not be issue in PHP 5.6 anymore, because you can use... use function ProcessWire\__; But how to deal with it in PHP 5.5? May be I could extend class Utils from some PW class to make $this->__() accessible? I mean... class Utils extends ProcessWire\ClassWithTranslationMethod { public function func() { $this->__('car'); } } Or do you see other solution? Thank you for all your ideas. Martin
  3. 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.
  4. 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
×
×
  • Create New...