$page->data() method

Get or set a low-level data value

Like get() or set() but will only get/set from the WireData's protected $data array. This is used to bypass any extra logic a class may have added to its get() or set() methods. The benefit of this method over get() is that it excludes API vars and potentially other things (defined by descending classes) that you may not want.

  • To get a value, simply omit the $value argument.
  • To set a value, specify both the $key and $value arguments.
  • If you omit a $key and $value, this method will return the entire data array.

Example

// Set a property
$item->data('some_property', 'some value');

// Get the value of a previously set property
$value = $item->data('some_property'); 

Usage

// basic usage
$array = $page->data();

// usage with all arguments
$array = $page->data($key = null, mixed $value = null);

Arguments

NameType(s)Description
key (optional)string, array

Property you want to get or set, or associative array of properties you want to set.

value (optional)mixed

Optionally specify a value if you want to set rather than get. Or Specify boolean TRUE if setting an array via $key and you want to overwrite any existing values (rather than merge).

Return value

array WireData null

Returns one of the following:

  • mixed - Actual value if getting a previously set value.
  • null - If you are attempting to get a value that has not been set.
  • $this - If you are setting a value.

$page methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #515
    In the 515th issue of ProcessWire Weekly we’ll check out the latest core updates, new modules, and more. Read on!
    Weekly.pw / 23 March 2024
  • Invoices Site Profile
    The new invoices site profile is a free invoicing application developed in ProcessWire. It enables you to create invoices, record payments to them, email invoices to clients, print invoices, and more. This post covers all the details.
    Blog / 15 March 2024
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani