Quote from: jrotering at Jan 11, 2011, 08:56 AM
So - let my try and re-state what I think I’m hearing you say: $resource->getContent() is the preferred / best practice way to get the actual content from a resource, because get(’content’) can mean different things depending on whether its used with a resource, chunk, snippet, etc.
Is that right?
Yes, in fact get(’content’) with anything but a resource will generally get you nothing at all. get() is a very low-level method -- a method of the xPDO object.
The argument to get() is the name of a specific column in the DB. For legacy reasons, the "content" field is ’snippet’ for snippets and ’htmlsnippet’ for chunks (though it’s ’content’ for templates).
getContent() is a higher-level method -- a method of the MODx object itself (resource, template, snippet, chunk, etc.). Each object knows how to return its own "content" fields when that method is called (by calling get() with the appropriate field name).
That’s not to say you should never use get(’whatever’). If you know what you’re doing and speed is critical, calling get(’content’) is a tiny bit faster, but if the field name ever changes (and that could happen in future releases), your code could break.