2011-05-03, 00:11:53
RobA Wrote:Off the top of my head I'd prefer a simplexml file/variable rather than a flat array, set up something like this:
...
So every page has a set of children that are the fields of the page, and a <subpage> child that can recursively hold more pages.
I'd also like to see the page nodes arranged as per the menu-order parameters. so it would be ewasy to get a next/previous page from the structure.
-Rob A>
From my experience the best approach is to have a flat XML file with each entry looking like a page file without content.
On the first request for cached data the core would read the file and build a structure like this:
Code:
$cached_data = array(
'url1' => array( 'url' => 'url1', 'parent' => 'parenturl1', ...,
'date' => <Unix timestamp, not string>,
'children' => array('childurl1', 'childurl2', ...)
'url2' => array(...),
...
'' => array('children' => array('toplevelurl1', 'toplevelurl2', ...))
);
(slug = url)
The order of the children entries should represent the order as defined by priority.
Additionally there is an "empty" entry with the toplevel pages.
This way you can
- easily access any page data by slug: $cached_data['slug']
- easily sort the entries by any metadata like publication date or name
- easily traverse from any page upwards to the toplevel page (bread crumbs):$url = 'url'; while ($url = $cached_data[$url]['parent']) do something;
- easily create a full menu by starting with $cached_data['']['children']
- easily create a child menu of any page by starting with $cached_data['pageurl']['children']