Jump to main content Jump to doc navigation

xPDO::newObject

Creates a new instance of a specified class. All new objects created with this method are transient until xPDOObject::save() is called the first time and is reflected by the xPDOObject::$_new property.

Syntax

API Docs: https://api.modx.com/revolution/2.2/db_core_xpdo_xpdo.class.html#\xPDO::newObject()

object|null newObject (string $className, [array $fields = array ()])

Example

Create a new Box object:

$box = $xpdo->newObject('Box');

Create a new Box object with the width and height already set:

$box = $xpdo->newObject('Box',array(
   'width' => 10,
   'height' => 4,
));

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
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Digital Penguin
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Snow Creative
  • Nick Clark
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard

Budget

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

Learn more