I am not getting it … Can you help me with my code ?
Here is my full code -
class MyControllerResources extends modRestController {
public $classKey = 'modResource';
// public $defaultSortField = 'sortorder';
public $defaultSortDirection = 'ASC';
// ['tvvalue'] = $object->getTVValue('tvname');
public $defaultSortField = 'id';
// public $defaultSortDirection = 'DESC';
public function prepareListObject(xPDOObject $object) {
$data = array();
$data['pagetitle'] = $object->pagetitle;
$data['content'] = $object->content;
$data['introtext'] = $object->introtext;
$data['longtitle'] = $object->longtitle;
$data['description'] = $object->description;
$data['featuredimage'] = $object->getTVValue('myimagetv');
$data['kitnelog'] = $object->getTVValue('mysimpletexttv');
return $data;
}
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,
)));
}
$objectArray = $this->object->toArray();
$objectArray += array(
'featuredimage' => $this->object->getTVValue('myimagetv'),
'kitnelog' => $this->object->getTVValue('mysimpletexttv')
);
unset(
$objectArray['alias'],
$objectArray['alias_visible'],
$objectArray['parent'],
$objectArray['type'],
$objectArray['contentType'],
$objectArray['link_attributes'],
$objectArray['published'],
$objectArray['pub_date'],
$objectArray['isfolder'],
// $objectArray['introtext'],
$objectArray['richtext'],
$objectArray['template'],
$objectArray['menuindex'],
$objectArray['searchable'],
$objectArray['cacheable'],
$objectArray['createdby'],
$objectArray['createdon'],
$objectArray['editedby'],
$objectArray['editedon'],
$objectArray['deleted'],
$objectArray['deletedon'],
$objectArray['deletedby'],
$objectArray['published'],
$objectArray['unpub_date'],
$objectArray['publishedon'],
$objectArray['publishedby'],
$objectArray['menutitle'],
$objectArray['donthit'],
$objectArray['privateweb'],
$objectArray['privatemgr'],
$objectArray['content_dispo'],
$objectArray['hidemenu'],
$objectArray['class_key'],
$objectArray['context_key'],
$objectArray['content_type'],
$objectArray['uri'],
$objectArray['uri_override'],
$objectArray['hide_children_in_tree'],
$objectArray['show_in_tree'],
$objectArray['properties']
);
$afterRead = $this->afterRead($objectArray);
if ($afterRead !== true && $afterRead !== null) {
return $this->failure($afterRead === false ? $this->errorMessage : $afterRead);
}
return $this->success('',$objectArray);
}
}