Jump to main content Jump to doc navigation

modResource.setProperties

Writes a whole namespace of properties in one call. With $merge set, $newProperties is merged over the values already in the namespace. Keys you leave out keep their previous values; with $merge false the namespace is replaced entirely. Other namespaces are never touched.

Returns the result of the field assignment; nothing reaches the database until save().

Syntax

boolean setProperties (array $newProperties [, string $namespace = 'core' [, boolean $merge = true]])
  • $newProperties (array) properties to write
  • $namespace (string) namespace to write into, by default 'core'
  • $merge (boolean) merge with the existing namespace instead of replacing it, by default true

Example

$resource = $modx->getObject('modResource', array('id' => 5));
$resource->setProperties(array('color' => 'foobar', 'size' => '10'), 'mycomponent');
$resource->setProperties(array('color' => 'bar'), 'mycomponent', false);
$resource->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

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

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

Learn more