run()

public static function run(string $module_method, mixed $data = null): mixed

Description

Executes a module controller method from anywhere - controllers, views, or models - by passing the module/method string and optional data. Accepts any PHP data type as the second parameter.

Parameters

Parameter Type Description
$module_method string The target module and method in "Module/Method" format (e.g. 'users/stats')
$data mixed (optional) Data to pass to the target method. Accepts any PHP type: strings, integers, arrays, objects, booleans, or null.

Return Value

Type Description
mixed Returns whatever the target method returns. No type restriction.

Example #1: Passing a String

PHP
$result = Modules::run('email/send', '[email protected]');

Example #2: Passing an Integer

PHP
$profile = Modules::run('users/get_profile', 88);

Example #3: Passing an Array

PHP
$order_data = [
    'order_id' => 12345,
    'customer' => 'Jane Smith',
    'items' => [
        ['id' => 1, 'qty' => 2, 'price' => 19.99]
    ]
];
$invoice = Modules::run('orders/generate_invoice', $order_data);

Example #4: Passing null

PHP
$default_view = Modules::run('dashboard/load_default', null);

Notes

  • The Modules::run() method is callable from controllers, views, and models
  • The first parameter must be in Module/Method format - case-insensitive for both segments
  • If the target module is a child module, use hyphenated format: 'parent-child/method'
  • When $data is null, the target method is called without parameters
  • Throws Exception if the controller or method is not found