Jump to content


fnode

Member Since 06 Sep 2011
Offline Last Active Sep 28 2012 10:35 AM
-----

Posts I've Made

In Topic: ProcessWire Form Builder

05 September 2012 - 11:20 PM

Super awesome!

That is a crazzzzy form builder!

Thank you!

In Topic: $pages scope

06 August 2012 - 10:04 AM

Code is working now! Thanks!

libs/paypal/ipn.php

<?php
include ("../../index.php");

$productid = $wire->pages->get(1332);

var_dump($productid);
?>

In Topic: $pages scope

06 August 2012 - 09:49 AM

Thank you Pete!

In Topic: excluding parent's title

29 March 2012 - 08:30 PM

Thank you, Soma for your help. It's working now. The code you gave me, helped me. I just added the the following:

<?php
if($p->numChildren){

	foreach($page->get($p->name) as $fo){
			if(count($fo->get($fo->name))){
			   foreach($fo->get($fo->name) as $f1){
				  $fielddata->import($f1);
			   }
			}
		 }
} else {
   foreach($page->get($p->name) as $fo){
	   $fielddata->import($fo);
}

FROM YOUR CODE

then how about like this?

function Pagefields(Page $page){  
	
	$fielddata = new PageArray();

	foreach($page->uses as $p){
		foreach($page->get($p->name) as $fo){
			if(count($fo->get($fo->name))){
				foreach($fo->get($fo->name) as $f1){
					$fielddata->import($f1);
				}
			}
		}
	}
	return $fielddata;
}

foreach(Pagefields($page) as $p){
	echo "<p>$p->title</p>";
}

.... edited code a little.


MY FINAL VERSION

<?php

function Pagefields(Page $page){

  $fielddata = new PageArray(); // Nice !

  foreach ($page->uses as $p){

	  if($p->numChildren){ // line added

		 foreach($page->get($p->name) as $fo){
			if(count($fo->get($fo->name))){
			   foreach($fo->get($fo->name) as $f1){
				  $fielddata->import($f1);
			   }
			}
		 }

	  } else { // lined added
		 foreach($page->get($p->name) as $fo){
			$fielddata->import($fo);
		 }
	  }

   } #endof: foreach($page->uses as $p){}

  return $fielddata; // Return me some data!
}

foreach(Pagefields($page) as $p){
  echo "<p>$p->title</p>"; // Yes, I got data!
}


Thank you again for your big help. Awesome Community! ;)

In Topic: excluding parent's title

28 March 2012 - 06:24 PM

Yes, you are correct I had to use strtolower($fo->title) for it to match or it will not work. $fielddata needs to returned data in each foreach loop.

then how about like this?

function Pagefields(Page $page){  
	
	$fielddata = new PageArray();

	foreach($page->uses as $p){
		foreach($page->get($p->name) as $fo){
			if(count($fo->get($fo->name))){
				foreach($fo->get($fo->name) as $f1){
					$fielddata->import($f1);
				}
			}
		}
	}
	return $fielddata;
}

foreach(Pagefields($page) as $p){
	echo "<p>$p->title</p>";
}

.... edited code a little.


My code
<?php

function Pagefields(Page $page){

  $fielddata = new PageArray();

   foreach($page->uses as $p){

	  //var_dump($p->title); // OUTPUTS. instances and categories

	  foreach($page->get($p->name) as $fo){
		 //var_dump($fo->title); // OUTPUTS. Categories and 2D

		 // I need to $fielddata also in this foreach loop, so it returns (categories) in this page.
		 // Or, it will not return [2D] as the selected item in categories.
		 // But is not returning
		 $fielddata->import($fo);

		 // I changed the name to match with (categories) it was category before. So, I do not use strtolower($fo->title) function.
		 if(count($fo->get($fo->name))){
			foreach($fo->get($fo->name) as $f1){
			   var_dump($f1->title); // Yes, It outputs. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. No errors if I add another instance in (instances).
			   $fielddata->import($f1);
			}
		 }
	  }
   } #endof: foreach($page->uses as $p){}

  return $fielddata;
}

foreach(Pagefields($page) as $p){
  //echo "<p>$p->title</p>";
  //var_dump($p->title);
}

Thank you for helping me.

EDIT : Attached file Pic #1 Pagefields > has 2 children assets and instances, it has 2 children categories and tags. Instances Page holds Categories and Tags, as you can see in Attached file # 1 if one of them matches I will get its data. Attached file Pic #1