Jump to main content Jump to doc navigation

modChunk::save

Writes the Chunk record to the database. The call goes through modElement::save, which also synchronizes the external file of a static Chunk.

Both events fire only when the instance is a modX: OnChunkBeforeSave before the write, OnChunkSave after it succeeded. Each event receives the mode (new or upd), a reference to the chunk, and the cacheFlag.

A listener can modify the Chunk because the write happens after the event. Listener return values are ignored, so the save cannot be aborted from an event. A failed write is logged as chunk_err_create for a new Chunk or as chunk_err_save for an existing one.

Syntax

boolean save ([boolean|integer $cacheFlag = null])
  • $cacheFlag (boolean|integer) Whether the record is cached; an integer is the lifetime in seconds, by default null. Both events receive it as a parameter.
  • Declared in modChunk (core/src/Revolution/modChunk.php), wraps modElement::save (core/src/Revolution/modElement.php).

Example

$chunk = $modx->newObject('modChunk');
$chunk->fromArray([
    'name' => 'MyChunk',
    'content' => '<p>Hello!</p>',
]);
$chunk->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