fromArray
Last updated Apr 6th, 2019 | Page history | Improve this page | Report an issue
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.
Backers
Budget
$301 per month—let's make that $500!
Learn morexPDOObject::fromArray()¶
Sets object fields from an associative array of key => value pairs.
Syntax¶
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]
)
Examples¶
Input the name of a person from an array.
$object->fromArray(array(
'fname' => 'Boo',
'lname' => 'Radley',
));
echo $object->get('fname').' '.$object->get('lname');
// prints "Boo Radley"
Strip 'ghost_' prefixes from the array provided:
$object->fromArray(array(
'ghost_fname' => 'Nearly Headless',
'ghost_lname' => 'Nick',
),'ghost_');
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...
);
$page->fromArray($data);
$page->save();
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.
Backers
Budget
$301 per month—let's make that $500!
Learn more