Search the blog

ProcessWire‘s wire() function gives you access to pretty its entire API. But if you use your own namespace then wire() will not be available since it is in the ProcessWire namespace (although it is available in the global namesapce once you are in a template).

Assuming you are writing your own namespace’d classes for your application/website there are serveral ways to make wire() available.

  1. Add use function ProcessWire\wire after your namespace declaration; this will alias wire() and make it available in that file/class
  2. Call \ProcessWire\wire(); although more verbose this will work from anywhere
  3. Use the ProcessWire namespace for your classes
  4. Add a wire() function in the global namespace that accesses \ProcessWire\wire() (see function below):

A global wrapper for wire():

function wire($key, …) {
	
    return \ProcessWire\wire($key, …);
	
}
Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.