Jump to content

LostKobrakai

PW-Moderators
  • Posts

    4,954
  • Joined

  • Last visited

  • Days Won

    100

Community Answers

  1. LostKobrakai's post in How to get all possible values stored for a field was marked as the answer   
    I think the mysql variant would certainly be the most performant. Otherwise you'd need to load all pages holding that field into memory, which is probably not your intend.
  2. LostKobrakai's post in Save a value when a page is added using ready.php hook was marked as the answer   
    $event->object will always give you the object the hook function is on. In this case it's pages.
    $pages->addHookAfter("added", function($event) { // $pages = $event->object; $page = $event->arguments(0); if($page->template->id == 46) { $page->setAndSave('text_1', "test"); } });
  3. LostKobrakai's post in How to output multilanguage string inside a multiline variable? was marked as the answer   
    The heredoc syntax behaves exactly like double-quote strings in a single line. Both do not support calling a function in it, only class methods or anonymous functions, see here for examples: http://stackoverflow.com/questions/10002652/in-php-how-to-call-function-in-string
    Edit:
    What might work is this, as templates while mostly using local variables are still executed in class context.
    $a = <<<EOT My {$this->_x('text', 'noun')} EOT; Edit2:
    You're also using nowdoc instead of heredoc, which does not allow for variable substitution at all, like single-quote strings. See here: http://php.net/manual/de/language.types.string.php#language.types.string.syntax.heredoc
  4. LostKobrakai's post in Getting Amazon AWS SDK to work with PW was marked as the answer   
    The code example probably expects you to be in a non namespaced environment, where it would work. You need to either use a "use" statement in the beginning of your file or call the class with a leading backslash \Aws\S3….
  5. LostKobrakai's post in navigation by page-field was marked as the answer   
    If it's single page than use "$page->category->id == $child->id"
  6. LostKobrakai's post in Will db queries for the same field taken only once or every time the field appear on the page? was marked as the answer   
    Even pages are most of the time queried once and after that cached. And their fields are as well only loaded once on first demand of it, as long as it's not autojoin field, which are automatically loaded with the pages native data (id, template, …).
  7. LostKobrakai's post in how to compare a password for changing password ? was marked as the answer   
    Just like you're comparing it for the login: hash the "current password" and compare it with the database entry. But pw does have you covered:
    $user->pass->matches($inputPass);
  8. LostKobrakai's post in Selector with two fields using OR operator fails was marked as the answer   
    parent is not a field in the traditional sense, but a native field and might therefore function a bit different. You could try:
    rel=(parent=$page), rel=(secondary_category=$page), …
  9. LostKobrakai's post in Get only the pages (categories) which are referenced by other pages was marked as the answer   
    https://processwire.com/talk/topic/9730-get-pages-used-by-a-pagefield/
  10. LostKobrakai's post in Show user information to everyone was marked as the answer   
    You could try this one to check it the selector syntax is the issue or something else. 
    $customUserRoles = $roles->find("name^=member-"); $profileTemp = $users->find("roles=$customUserRoles");
  11. LostKobrakai's post in Use each page field values just one time in the admin was marked as the answer   
    You can use the php selection for the pagefield and remove all cities. which are already linked. 
  12. LostKobrakai's post in Return to home page is always to English (default) language was marked as the answer   
    $config->urls->root doesn't have anything to do with the pagetree, especially on multi-language setups. It's much rather intended to be used as variable if processwire is installed in the root directory ( /… ) or in a subdirectory ( /mySubdirectory/… ). 
  13. LostKobrakai's post in 2500 queries for a single pageview? Is that normal? was marked as the answer   
    You certainly need to keep mysql connections and mysql queries apart. The first one is causing your db to crash, whereas the latter ones are using these connections. If 30 visitors are causing 400 (I'd expect concurrent) connections I'd check if mysql connections are properly closed.
  14. LostKobrakai's post in Cannot preview code internalisation translation was marked as the answer   
    You mentioned your pages having different urls, while having the same name supplied: /home/contact/ vs. /contact. The /home part is probably because of the name settings of the homepage. It lets you choose if you want all multilanguage pages to be under the same url or namespaced as /en/…, /es/… or whatever name you want to be there.
  15. LostKobrakai's post in Filter find() by pages selected in page field was marked as the answer   
    id!=$page->myPageFieldWithPagesNotToBeLoaded Like that?
  16. LostKobrakai's post in How to get array of page ids by selector if there are 10000+ pages? was marked as the answer   
    $pages->find($selector, array('returnVerbose' => false, 'loadPages' => false));

  17. LostKobrakai's post in How to get children/subpages of a user was marked as the answer   
    You probably shouldn't store site content inside the Admin folder, as there are various pages, which are hidden, not viewable by non-superuser and such things. So you'd need to use include=hidden or check_access=0 just to make things work. I'm personally not a fan of this, as any errors made in selectors could lead to being a security hole. I'd rather use a page-field to link users to orders and store the orders under a different parent outside of the admin branch.
  18. LostKobrakai's post in Access value of a multidimensional associative array Element inside the same array was marked as the answer   
    All the $pages->find() calls are evaluated while creating $stats, which in turn means $stats is not defined at that moment. If you want the count to run "on-demand" you'd need to look into using anonymous functions. 
    Also using $pages->find()->count is most of the time an anti-pattern. If you're not using those pages, but only the count rather user $pages->count($selector). The latter does only count the pages in the db, whereas your version does load all those pages and does count them in memory (php). 
    Edit:
    Just to make things more clear about the array creation. You're building up an array and after the whole array is computed – with all dynamic calls being evaluated to static values – you're saving the data into the variable $stats. You could go another way like this:
    $stats = array(); // Create array; $stats !== undefined $stats["total"] = array( ["main"] => array(), ["yes"] => array() ); // Update each value one at a time $stats["total"]["main"]["selector"] = "template=50, parent=$formSuperSelector"; $stats["total"]["main"]["count"] = $this->pages->count($stats['total']['main']['selector']); …
  19. LostKobrakai's post in Button next sibling was marked as the answer   
    https://processwire.com/talk/topic/12147-continuous-prevnext-links/
  20. LostKobrakai's post in Need help optimising list of page filters based on page field options (too many queries) was marked as the answer   
    You might take a look at this:
    https://processwire.com/talk/topic/9730-get-pages-used-by-a-pagefield/
  21. LostKobrakai's post in How to output failed login attempts on frontend was marked as the answer   
    https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Session/SessionLoginThrottle/SessionLoginThrottle.module#L85-L90
  22. LostKobrakai's post in 2 pagers on a single template was marked as the answer   
    You can render two independent paginations, but only use one at a time. You'd use the getVars option or $input->whitelist() (if you need some filter values to be populated as well) to add a kinda "switch" GET variable, which tells you which pagination is currently used. When you know which pagination was clicked you can manually set the "start=" part to only the selector of the clicked pagination. There's no automated way to differenciate multiple paginations. 
  23. LostKobrakai's post in Create and compare pageArrays. was marked as the answer   
    $pa1 = $pages->find("something");
    $a2 = array();
    foreach(){…}
    $pa2 = (new PageArray())->import($a2);
    foreach($pa1->import($pa2)->unique() as $p){
    if($pa2->has($p)) …
    else …
    }

  24. LostKobrakai's post in Selector problem with multiple keywords in multiple fields was marked as the answer   
    As Macrura proposed: Run the query for each $part in isolation and in the end merge the results.
    $results = array(); foreach($parts as $part){ // Might be optimized to only retrieve IDs in the first place $result = $pages->find("something=$part"); $results[] = $result->explode("id"); } // Get all the id's present in all results $intersect = array_reduce($results, function($carry, $item){ if(is_null($carry)) return $item; return array_intersect($carry, $item); }); // Get the real search results $search_result = $pages->get("id=" . implode("|", $intersect));
  25. LostKobrakai's post in filter repeater enries by date was marked as the answer   
    Your version is not working because the runtime selector currently does not support parsing "today" to it's timestamp like the db selector engine does.
    $pages->find("template=repeater_events, end_date>today, sort=end_date, limit=2"); $pages->get("template=events")->events->find("end_date>" . time() . ", sort=end_date, limit=2");
×
×
  • Create New...