GetSimple Support Forum
returnPageField - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Developer Discussions (http://get-simple.info/forums/forumdisplay.php?fid=8)
+--- Thread: returnPageField (/showthread.php?tid=4713)



returnPageField - Carlos - 2013-05-07

I want to read the parent of a slug in a plugin, if possible without reading the slug xml file.

- In the frontend I cannot use returnPageField($slug,'parent') before index-pretemplate (it's still not defined)

- In the backend (the plugin page) the function is available but doesn't work - I get these errors:
Code:
Notice: Undefined index: my-slug in [...]\admin\inc\caching_functions.php on line 114

Warning: array_key_exists() expects parameter 2 to be array, null given in [...]\admin\inc\caching_functions.php on line 114
(I suppose it's because $pagesArray has not been populated.)

Any other recommended way to do this?


RE: returnPageField - shawn_a - 2013-05-07

What version ?

Well its a plugin so I guess all versions preferably.

3.2 or 3.2.1+ ( dont recall ) load page cache on index-header now, and eventually we will have lazy loading.

for now you can probably just check $pagesArray and call
getPagesXmlValues(false) if not set first.


RE: returnPageField - Carlos - 2013-05-07

Thank you, but as I only need to find out one parent, I prefer not calling getPagesXmlValues as it would be an extra file read (what I want to avoid).

I was testing with GS 3.2.1 but I've just tried with 3.2.0 and 3.1.2 too.
It seems that, when in index-pretemplate, returnPageField only works since 3.2.1 (so I assume the index-header cache loading was introduced in this version)

This is what I might do to get the parent slug:

Code:
// if version>3.2.0 and is frontend
if (function_exists('get_gs_version') && get_gs_version() >= '3.2.1' && (basename($_SERVER['PHP_SELF']) == 'index.php') ) {
  ... use returnPageField ...
} else {
  .... read page xml  ....
}



RE: returnPageField - shawn_a - 2013-05-07

why not just check if pagesarray is empty, and pull the the file manually if you need it. Instead of checking versions.


RE: returnPageField - Carlos - 2013-05-08

I'm assuming that get_gs_version and returnPageField will work the same way in future GS versions.

I could check and directly get values from $pagesArray, but I think I cannot be so "sure" it will work the same (name, structure, contents) in the future (when GS uses lazy loading or whatever).


RE: returnPageField - shawn_a - 2013-05-08

It will always work the same. $pagesArray IS the global pagecache.

we might add wrappers to abstract it like getPageCache() and add lazy loading to it. ( in fact i already have most of this plumbed in for 3.3)

But you can use $pagesArray just fine.


RE: returnPageField - Carlos - 2013-05-08

Is this like what you suggest?

Code:
global $pagesArray;
if ($pagesArray) {
   ... use returnPageField ....
} else {
   ... read xml file ...
}



RE: returnPageField - shawn_a - 2013-05-08

yup, you might have to use count() == 0

I am pretty sure caching_functions does a
$pagesArray = array();

So its an empty array when its initialized.


RE: returnPageField - Carlos - 2013-05-09

No need to use count. An empty array evaluates to false (I had tested and worked for me, but just in case I searched and found it's how PHP works)

I'll use if($pagesArray) then. Thank you for your comments!