PHP Source Code

function sanitizeObject($object, $keepFields = array()) {
		$out = array();
		if ($keepFields) {
		       	foreach ($keepFields as $field) {
                            if ($obj instanceof xPDOObject){
				$out[$c++][$field] = $object->get($field);
		return $out;


xPDO has an amazing ability of streamlining database to presentation translations, but in some scenarios simply providing an xPDO object to a presentation method, such as $modx->getchunk('chunkName', $object) may allow undesirable information onto the page.

I created this function to sanitize Object values before they are sent to any display mechanism.


sanitizeObject($obj, array('skuId', 'minAmount', 'maxAmount'))

In this article