Jump to content

Get specific page attributes/fields from pagearray set


Bill
 Share

Recommended Posts

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

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

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 by Bill
Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

  • 8 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...