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:
- Injection of dependencies to Wire derived objects:
Most Wire derived objects also support access to API variables directly via
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.
// 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());
// basic usage $mixed = $wire->wire(); // usage with all arguments $mixed = $wire->wire($name = '', $value = null, bool $lock = false);
Name of API variable to retrieve, set, or omit to retrieve the master ProcessWire object.
Value to set if using this as a setter, otherwise omit.
When using as a setter, specify true if you want to lock the value from future changes (default=false).
Method can throw exceptions on error:
API reference based on ProcessWire core version 3.0.178