Bill Posted March 22, 2012 Author Share Posted March 22, 2012 Thanks for the very thorough explanation. Lovin' it. Link to comment Share on other sites More sharing options...
ryan Posted March 23, 2012 Share Posted March 23, 2012 Right this is with the debug already set to TRUE. It's like it churns, churns, etc... on my localhost and then stalls out... nothing, no unseen html either... the page source is blank. Only (i mean ONLY) when i do the find('template=cool-page') syntax. I'm still wondering about this, since it sounds like its not working correctly here. What is the scale of pages in your site using the template 'cool-page' and what auto join fields does that template have? I'm just trying to find out as much info as possible to be able to reproduce it. Just curious, why is it an abstract call to that method, and not directly... conversely, if i used it to only extend the PageArray and implement Module, then wouldn't it be a direct call? Not sure I understand the question 100% so let me know if i don't answer it right. The class::method syntax when you add the hook is just a way of communicating to PW that you want to hook all current and future instances. Kind of like a jQuery live() event. This is consistent to how you'd usually refer to a class::method in documentation, outside of a specific instance. If you only wanted to hook one instance then the syntax would be $objectToHook->addHook('method', $myObject, 'myMethod'); and $myObject is most commonly $this. Link to comment Share on other sites More sharing options...
Bill Posted March 23, 2012 Author Share Posted March 23, 2012 I'm still wondering about this, since it sounds like its not working correctly here. What is the scale of pages in your site using the template 'cool-page' and what auto join fields does that template have? I'm just trying to find out as much info as possible to be able to reproduce it. I only have about 100 pages (nothing to sneeze at...). ... This is consistent to how you'd usually refer to a class::method in documentation, outside of a specific instance. If you only wanted to hook one instance then the syntax would be $objectToHook->addHook('method', $myObject, 'myMethod'); and $myObject is most commonly $this. Got it now. The "::" abstract call was throwing me off a bit was all. Bill Link to comment Share on other sites More sharing options...
Bill Posted March 23, 2012 Author Share Posted March 23, 2012 (edited) Module :: HelperAttributes <?php /** * ProcessWire 'HelperAttributes' module * * Adds a getAttr() method to all PageArrays * * ProcessWire 2.x * Copyright (C) 2012 by Bill Ortell * (acknowledgements: Ryan Cramer) * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * */ /** * adapted from example thrown in by Ryan Cramer on this thread: * http://processwire.com/talk/topic/1083-get-specific-page-attributesfields-from-pagearray-set/page__pid__9500#entry9500 */ class HelperAttributes extends Wire implements Module { static public function getModuleInfo() { return array( 'title' => 'Get Page Attributes', 'version' => 100, 'summary' => 'Adds "getAttr()" method - get any {one} attribute from all pages in PageArray', 'href' => 'http://processwire.com/talk/topic/1083-get-specific-page-attributesfields-from-pagearray-set/', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('PageArray::getAttr', $this, 'getAttr'); } public function getAttr(HookEvent $event) { $pageArray = $event->object; $key = $event->arguments[0]; $pageKeys = array(); foreach ($pageArray as $page) { $pageKeys[] = $page->$key; // all pages have one! } $event->return = $pageKeys; } } The above was saved to a HelperAttributes.module and placed into my site/modules folder IF ANYTHING - someone will find this helpful in starting their own module (possibly?) Edited March 23, 2012 by Bill Link to comment Share on other sites More sharing options...
WillyC Posted March 23, 2012 Share Posted March 23, 2012 soma yo can no| $wire->zam in modulos o classos. wire('zam') must it.be bill getAttr beauty i.use good,thanking 1 Link to comment Share on other sites More sharing options...
Bill Posted March 23, 2012 Author Share Posted March 23, 2012 Thanks... (high-five with all of you for helping me with it!) Link to comment Share on other sites More sharing options...
Soma Posted March 23, 2012 Share Posted March 23, 2012 Bill I still don't get what this would do any different than simply doing this: $keys = explode("|", $pagearray); Except that this module will load on every page load. Bear with me, as I'm maybe missing the obvious. Dumb me, now I get it! It's not only about id's Link to comment Share on other sites More sharing options...
Bill Posted March 28, 2012 Author Share Posted March 28, 2012 I'm still wondering about this, since it sounds like its not working correctly here. What is the scale of pages in your site using the template 'cool-page' and what auto join fields does that template have? I'm just trying to find out as much info as possible to be able to reproduce it. I think i know the issue... kinda wild tho - not sure if it's a buffering limit or what... as i'm on my localhost.. (shrug). Its when I do var_dump of the 'children' objects, etc.. any time i seem/tend to dump that to the screen, then i'm seizing up the system, and it gives me the 'white-wall-of-doom!' When i remove it, ir do the var_dump on anything else (obviously smaller than the children object array, etc...) it's all fine. Bill p.s. er so it seems 1 Link to comment Share on other sites More sharing options...
ryan Posted March 29, 2012 Share Posted March 29, 2012 Bill, that actually makes sense. I've done a var_dump on pages before, and it basically becomes an infinite loop (or something close to it). Link to comment Share on other sites More sharing options...
LAPS Posted November 2, 2020 Share Posted November 2, 2020 About the original topic and just for future reference, here I add a way of doing things using explode. $p_ids = $pageArray->explode('id'); 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