Jump to main content Jump to doc navigation


Sets object fields from an associative array of key => value pairs.


API Docs: http://api.modxcms.com/xpdo/om/xPDOObject.html#fromArray

void fromArray(
   array $fldarray,
   [string $keyPrefix = ''],
   [boolean $setPrimaryKeys = false],
   [boolean $rawValues = false],
   [boolean $adhocValues = false]


Input the name of a person from an array.

    'fname' => 'Boo',
    'lname' => 'Radley',
echo $object->get('fname').' '.$object->get('lname');
// prints "Boo Radley"

Strip 'ghost_' prefixes from the array provided:

    'ghost_fname' => 'Nearly Headless',
    'ghost_lname' => 'Nick',
echo $object->get('fname').' '.$object->get('lname');
// prints "Nearly Headless Nick"

Creating a MODX resource:

$page = $modx->newObject('modResource');

$data = array(
    'pagetitle' => 'My Page',
    'description' => 'Why not?',
    // ... etc...


See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.



$0 per month—let's make that $500!

Learn more