Wire::wire() method

Get an API variable, create an API variable, or inject dependencies.

This method provides the following:

  • Access to API variables:
    $pages = $this->wire('pages');

  • Access to current ProcessWire instance:
    $wire = $this->wire();

  • Creating new API variables:
    $this->wire('widgets', $widgets);

  • Injection of dependencies to Wire derived objects:
    $this->wire($widgets);

Most Wire derived objects also support access to API variables directly via $this->apiVar.

There is also the wire() procedural function, which provides the same access to get API variables. Note however the procedural version does not support creating API variables or injection of dependencies.

Example

// Get the 'pages' API variable
$pages = $this->wire('pages');

// Get the 'pages' API variable using alternate syntax
$pages = $this->wire()->pages;

// Get all API variables (returns a Fuel object)
$all = $this->wire('all');

// Get the current ProcessWire instance (no arguments)
$wire = $this->wire();

// Create a new API variable named 'widgets'
$this->wire('widgets', $widgets);

// Create new API variable and lock it so nothing can overwrite
$this->wire('widgets', $widgets, true);

// Alternate syntax for the two above
$this->wire()->set('widgets', $widgets);
$this->wire()->set('widgets', $widgets, true); // lock

// Inject dependencies into Wire derived object
$this->wire($widgets);

// Inject dependencies during construct
$newPage = $this->wire(new Page());

Usage

// basic usage
$mixed = $wire->wire();

// usage with all arguments
$mixed = $wire->wire($name = '', $value = null, bool $lock = false);

Arguments

NameType(s)Description
name (optional)string, object

Name of API variable to retrieve, set, or omit to retrieve the master ProcessWire object.

value (optional)null, mixed

Value to set if using this as a setter, otherwise omit.

lock (optional)bool

When using as a setter, specify true if you want to lock the value from future changes (default=false).

Return value

mixed

Exceptions

Method can throw exceptions on error:

  • WireException


Wire methods and properties

API reference based on ProcessWire core version 3.0.178

Twitter updates

  • Today a new version of FormBuilder has been released in the FormBuilder support board (our 50th version) and it has a lot of interesting new features, which we’ll take a closer look at in this post— More
    11 June 2021
  • ProcessWire 3.0.179 adds great new admin theme customization tools that put you in full control over the Uikit admin styles— More
    28 May 2021
  • ProcessWire updates for week of 21 May 2021— More
    22 May 2021

Latest news

  • ProcessWire Weekly #369
    In the 369th issue of ProcessWire Weekly we're going to check out the latest core updates, showcase some recent forum highlights and tutorials, and more. Read on!
    Weekly.pw / 5 June 2021
  • ProcessWire 3.0.179 core updates
    ProcessWire 3.0.179 adds great new admin theme customization tools that put you in full control over the admin styles.
    Blog / 28 May 2021
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.