# Utilities

Calling static methods of classes defined in the system/utilities folder is quite easy, just use Utilities/{classname} before calling it and you are done. But the utility system is able to inject a class to all of yours controllers and extensions, giving you the ability to call its non-static methods.

The utilities that need to be called in a non-static way must be defined in the system/definitions/Utilities.php file.


Create a Example.php file inside the system/utilities folder with the following content:


namespace Utilities;

class Example

    public function sayHello()
        echo 'Hello world';

Now add the following code to your system/definitions/Utilities.php file:

Factory::addUtility('example', 'Example');

The first parameter is the name that will be used to refer to the class in the controllers. The second parameter is the utility class name.

Now, in your controllers or extensions you can call its methods and properties like this: