Wire is the base class for most ProcessWire classes and modules.

Wire derived classes have a $this->wire() method that provides access to ProcessWire's API variables. API variables can also be accessed as local properties in most cases. Wire also provides basic methods for tracking changes and managing runtime notices specific to the instance.

Wire derived classes can specify which methods are "hookable" by precending the method name with 3 underscores like this: ___myMethod(). Other classes can then hook either before or after that method, modifying arguments or return values. Several other hook methods are also provided for Wire derived classes that are hooking into others.


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon.

Common / Notices / Identification / For hooks / Hooks / Changes / Api helpers

Common

Name Return Summary  
Wire::wire() mixed Get an API variable, create an API variable, or inject dependencies.

Notices

Name Return Summary  
Wire::error($text) $this Record an non-fatal error message in the system-wide notices.
Wire::errors() Notices, array or string Return or manage errors recorded by just this object or all Wire objects
Wire::log() WireLog Log a message for this class
Wire::message($text) $this Record an informational or “success” message in the system-wide notices.
Wire::messages() Notices, array or string Return or manage messages recorded by just this object or all Wire objects
Wire::warning($text) $this Record a warning error message in the system-wide notices.
Wire::warnings() Notices, array or string Return or manage warnings recorded by just this object or all Wire objects

Identification

Name Return Summary  
Wire::className() string Return this object’s class name
Wire::getInstanceNum() int Get this Wire object’s instance number

For hooks

This methods are only useful for hooking and should not be called directly.

Name Return Summary  
Wire::callUnknown(string $method, array $arguments) null or mixed If method call resulted in no handler, this hookable method is called.
Wire::changed(string $what) (nothing) Hookable method that is called whenever a property has changed while change tracking is enabled.
Wire::trackException($e) $this Hookable method called when an Exception occurs

Hooks

Name Return Summary  
Wire::addHookAfter(string $method, $toObject) string Add a hook to be executed after the hooked method
Wire::addHookBefore(string $method, $toObject) string Add a hook to be executed before the hooked method
Wire::addHookMethod(string $method, $toObject) string Add a hook accessible as a new public method in a class (or object)
Wire::addHookProperty(string $property, $toObject) string Add a hook that will be accessible as a new object property.
Wire::getHooks() array Return all hooks associated with this class instance or method (if specified)
Wire::hasHook(string $method) bool Returns true if the method or property is hooked, false if it isn’t.
Wire::removeHook($hookId) $this Given a Hook ID, remove the hook

Changes

Name Return Summary  
Wire::getChanges() array Return an array of properties that have changed while change tracking was on.
Wire::isChanged() bool Does the object have changes, or has the given property changed?
Wire::resetTrackChanges() $this Clears out any tracked changes and turns change tracking ON or OFF
Wire::setTrackChanges() $this Turn change tracking ON or OFF
Wire::trackChange(string $what) $this Track a change to a property in this object
Wire::trackChanges() bool or int Returns true if change tracking is on, or false if it is not.
Wire::trackChangesOn const 2 For setTrackChanges() method flags: track names only (default).
Wire::trackChangesValues const 4 For setTrackChanges() method flags: track names and values.
Wire::untrackChange(string $what) $this Untrack a change to a property in this object

Api helpers

Name Return Summary  
Wire::array|string|int|null input($type = '', $key = '', $sanitizer = '') WireInput or WireInputData Access the $input API variable as a function.
Wire::cache($name = '', $expire = null, $func = null) WireCache or string or array or PageArray or null Access the $cache API variable as a function.
Wire::config($key = '', $value = null) Config or mixed Access the $config API variable as a function.
Wire::database() WireDatabasePDO Access the $database API variable as a function.
Wire::datetime($format = '', $value = '') WireDateTime or string or int Access the $datetime API variable as a function.
Wire::fields($name = '') Field or Fields or null Access the $fields API variable as a function.
Wire::files() WireFileTools Access the $files API variable as a function.
Wire::inputCookie($key = '', $sanitizer = '') WireInputData or string or int or array or null Access the $input->cookie() API variable as a function.
Wire::inputGet($key = '', $sanitizer = '') WireInputData or string or int or array or null Access the $input->get() API variable as a function.
Wire::inputPost($key = '', $sanitizer = '') WireInputData or string or int or array or null Access the $input->post() API variable as a function.
Wire::languages($name = '') Languages or Language or NullPage or null Access the $languages API variable as a function.
Wire::modules($name = '') Modules or Module or ConfigurableModule or null Access the $modules API variable as a function.
Wire::page($key = '', $value = null) Page or Mixed Access the $page API variable as a function.
Wire::pages($selector = '') Pages or PageArray or Page or NullPage Access the $pages API variable as a function.
Wire::permissions($selector = '') Permissions or Permission or PageArray or null or NullPage Access the $permissions API variable as a function.
Wire::roles($selector = '') Roles or Role or PageArray or null or NullPage Access the $roles API variable as a function.
Wire::sanitizer($name = '', $value = '') Sanitizer or string or int or array or null or mixed Access the $sanitizer API variable as a function.
Wire::session($key = '', $value = null) Session or mixed Access the $session API variable as a function.
Wire::templates($name = '') Templates or Template or null Access the $templates API variable as a function.
Wire::user($key = '', $value = null) User or mixed Access the $user API variable as a function.
Wire::users($selector = '') Users or PageArray or User or mixed Access the $users API variable as a function.