I'm using
MODX 2.2.10.
This works:
// Get Current ID
$page_id = $modx->resource->get('id');
$page = $modx->getObject('modResource',$page_id);
$uri = $page->get('uri');
$output .= "<p>".$uri."</p>";
// Returns page-uri.html
This doesn't:
// Get Current ID
$current_id = $modx->resource->get('id');
// Get Parent IDs (returned in an Array)
$parent_ids = $modx->getParentIds($current_id);
foreach($parent_ids as $key => $page_id){
$page = $modx->getObject('modResource',$page_id);
$uri = $page->get('uri');
$output .= "<p>".$uri."</p>";
}
I get this error:
Fatal error: Call to a member function get() on a non-object in
/core/cache/includes/elements/modsnippet/35.include.cache.php on
line 31
How come?
Jean-Marc Buytaert (@jmbuytaert)
MODX truly is the greatest thing that's ever happened to the Internet.
-
☆ A M B ☆
- 160 Posts
Try outputting $page_id in your second example, I can almost think this is blank.
-
MODX Staff
- 10,725 Posts
0 is a valid parent, but will not be an object.
Howdy!
Thanks for the quick reply.
$page_id returned both parent page ids.
When I do:
I get this:
Array
(
[0] => 12
[1] => 0
)
So... basically, I'm trying to get every parent IDs/alias/menutitle of a resource. How can I do that?
Jean-Marc Buytaert (@jmbuytaert)
MODX truly is the greatest thing that's ever happened to the Internet.
-
☆ A M B ☆
- 160 Posts
0 (zero) wouldn't be a ID in the database, so you would need to substitute that for 1, although I am against hard coding values.
Quote from: easylancer at Dec 31, 2013, 11:31 AM0 (zero) wouldn't be a ID in the database, so you would need to substitute that for 1, although I am against hard coding values.
That was it. To "fix" it, I did this:
// Get Current ID
$current_id = $modx->resource->get('id');
// Get Parent IDs (returned in an Array)
$parent_ids = $modx->getParentIds($current_id);
foreach($parent_ids as $page_id){
if($page_id != 0){
$page = $modx->getObject('modResource',$page_id);
$uri = $page->get('uri');
$output .= "<p>".$uri."</p>";
}
}
Thank you! And Happy New Year!
Jean-Marc Buytaert (@jmbuytaert)
MODX truly is the greatest thing that's ever happened to the Internet.