Hi everyone,
I've been playing with MODX over the past week or so and I've been digging into the api and playing with some of the functionality.
One thing I haven't been able to find is an obvious way to get all children of the root of the context.
For example, from the demo I've installed, the root of the context is 'web'... is there a convenient way for me to find all children of it?
I'm not interested in grandchildren (that's for next week), just the immediate children.
Thanks a million,
M
-
☆ A M B ☆
- 3,141 Posts
$children = $modx->getCollection('modResource', array( 'context_key' => 'web', 'parent' => 0));
which is the same as
$c = $modx->newQuery('modResource');
$c->where(array(
'context_key' => 'web',
'parent' => 0,
));
$children = $modx->getCollection('modResource',$c);
and you can use that array of modResource objects like this:
foreach ($children as $child) {
var_dump($child->toArray());
}
To get the children of the current resource you can do this:
$children = $modx->resource->getMany('Children');
or
$c = $modx->newQuery('modResource');
$c->where(array(
'context_key' => 'web',
'parent' => $modx->resource->get('id'),
));
$children = $modx->getCollection('modResource',$c);
Thanks so much Mark. I'm coming from an Etomite background and I'm still in shock from the extent of the MODX API. Think I'm trying too hard...
Your answer is very much appreciated.
Michael
-
☆ A M B ☆
- 3,141 Posts
The Revolution API is *very* different from Evo / Etomite... that's for sure