WireData::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 = $wireData->data();

// usage with all arguments
$array = $wireData->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.

WireData methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #539
    In the 539th issue of ProcessWire Weekly we'll share the latest weekly update from Ryan, check out a new third party module called AltTextGPT, and more. Read on!
    Weekly.pw / 7 September 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK