<?php
$id = 15;
$resource = $modx->getObject('modResource', (int) $id);
$resource->set('content', 'New content');
$resource->save();
?>Dave, I suggest you read through a few more general "MODX develop how-to's".
Doing what you want can be done in many different ways. Using xPDO getting/updating resources is very easy, you won't really need an API...you can script your own in 5 minutes.
Updating a resource through a snippet might look a little like this:
<!--?php $id = 15; $resource = $modx--->getObject('modResource', (int) $id); $resource->set('content', 'New content'); $resource->save(); ?>
If you want to know what fields you can update check out:
/core/model/schema/modx.mysql.schema.xml
And find the object class="modResource".
you can try formit and a formit-hook like formit2resource (somewhere in the forums) or newspublisher.
Yeah, that's what I'm looking at doing with the setContent() method. Correct me if I'm wrong, but is that not part of the MODx API? If it's not an API, what is it?
I'd still like to know if I need to do my own data sanitization before calling setContent as well.
Yeah, that's what I'm looking at doing with the setContent() method. Correct me if I'm wrong, but is that not part of the MODx API? If it's not an API, what is it?
I believe it is an API but it's more specifically a database API based on xPDO. Tomato tom-AH-to (FYI: NO ONE says tom-AH-to)
I'd still like to know if I need to do my own data sanitization before calling setContent as well.
Yes you will need to do your sanity checks.
No, I'm not talking about sanity checks. I'm talking about protecting against SQL injection. Do I need to strip slashes, check for and escape special characters, etc.? Data should never be taken from a form and put straight into a database. RedbeanPHP, for instance, does all that for you when you save data to a database using its API. Does xPDO do that as well?
Edit:
I'll bet it does. Redbean does it with PDO bindings so it seems similar. I'd like to be sure though before I go and skip it.