TV values for resources are not stored with the resource, but in a different table.
I think this would do it (assuming that 4 is the ID of the TV):
<?php
/* get the tvr for this resource */
$tvr = $modx->getObject('modTemplateVarResource', array ('tmplvarid'=>'4', 'contentid'=>$resource->get('id') );
/* create tvr if it doesn't exist yet */
if (empty ($tvr)) {
$tvr = $modx->newObject('modTemplateVarResource', array(('tmplvarid'=>'4', 'contentid'=>$resource->get('id') );
}
/* set the value and save */
$tvr->set('value', 'whatever');
$tvr->save();
You did’t understand me. Don’t need change tv in db. I need change it only when open Resource -> Create\Edit (only wiev). Resource variables I could change in $resource->set("pagetitle", "111"); How can I change tv-variable?
I understood you, but the Create/Edit Resource panel is going to show the value for that TV that’s in the DB (or the default value if no value is set). You can change the fields of the resource object, because MODX creates a handle to it before rendering the form. There’s no such thing (that I know of) for TVs.
You can change the default value of the TV in the form on the Create/Edit Resource panel with a Form Customization rule and use a constraint to limit the rule to a certain resource if that will meet your needs.
You could also change the default value for the TV itself if that would work.