<?php
class myControllerPosts extends modRestController{
public $classKey = 'modResource';
public $defaultSortField = 'id';
public $defaultSortDirection = 'DESC';
public function read($id) {
if (empty($id)) {
return $this->failure($this->modx->lexicon('rest.err_field_ns',array(
'field' => $this->primaryKeyField,
)));
}
/** @var xPDOObject $object */
$c = $this->getPrimaryKeyCriteria($id);
$this->object = $this->modx->getObject($this->classKey,$c);
if (empty($this->object)) {
return $this->failure($this->modx->lexicon('rest.err_obj_nf',array(
'class_key' => $this->classKey,
)));
}
$tvID = 17;
$tv = $this->modx->getObject('modTemplateVarResource', array('tmplvarid' => $tvID, 'contentid' => $id));
$objectArray = Array();
$objectArray ['id'] = $id;
$objectArray ['pagetitle'] = $this->object->pagetitle;
$objectArray ['alias'] = $this->object->alias;
$objectArray ['someTV'] = $tv->value;
$afterRead = $this->afterRead($objectArray);
if ($afterRead !== true && $afterRead !== null) {
return $this->failure($afterRead === false ? $this->errorMessage : $afterRead);
}
return $this->success('',$objectArray);
}
}{"message":"","object":{"id":"6","pagetitle":"someTitle","alias":"someAlias","someTV":null},"success":true}This question has been answered by BobRay. See the first response.
$objectArray['someTV'] = $this->object->getTVValue($tvID);