It means the $resource is null — no Resource with an id equal to the value of $parentID was found. You can’t call the method ->get() if you do not have a modResource object instance returned from the getObject() call.
-
- 24,544 Posts
You can test the return value from getObject() before calling get() to avoid the error:
$resource = $modx->getObject('modResource',$parentID);
if ($resource) {
$parent_parentID = $resource->get('parent');
}
For resources at the top level of the tree, the $parentID will be 0 because they have no parent, so trying to get their parent object will always fail.
-
- 2 Posts
Thanks for the replys, I will test out my code.
UPDATE: Added the conditional code and it works great. Would have been better if MODx made in error or sent to internal log rather than erroring in apache on the cache file...
Should I submit the error bit to the bug tracker?
-
- 24,544 Posts
You could make it a feature request, but I don’t know if there’s anything MODX or xPDO can do about this. Generally, all attempts to "get" any object should be tested to make sure you got the object successfully before calling any of the object’s methods. Calling any method of a non-object will always throw a PHP error.