Jump to content


Bill

Member Since 09 Feb 2012
Offline Last Active Nov 17 2012 11:29 PM
-----

Posts I've Made

In Topic: Get specific page attributes/fields from pagearray set

28 March 2012 - 03:08 PM

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

In Topic: Get specific page attributes/fields from pagearray set

23 March 2012 - 01:16 PM

Thanks...
(high-five with all of you for helping me with it!)

In Topic: Get specific page attributes/fields from pagearray set

23 March 2012 - 08:27 AM

Module :: HelperAttributes

<?php
/**
* ProcessWire 'HelperAttributes'  module
*
* Adds a getAttr() method to all PageArrays
*
* ProcessWire 2.x
* Copyright © 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! <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
  }
  $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?)

In Topic: Get specific page attributes/fields from pagearray set

23 March 2012 - 07:32 AM

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

In Topic: Get specific page attributes/fields from pagearray set

22 March 2012 - 12:47 PM

Thanks for the very thorough explanation. Lovin' it. :)