Helpers

SigmaPHP provides a set of global helper functions that simplify common tasks across the framework. These helpers are available everywhere in your application, including controllers, models, services, and even inside views and templates.

They are designed to reduce boilerplate code and provide quick access to frequently used framework features such as the container, configuration, routing utilities, and debugging tools.

d(...)

A simple debugging helper that prints the contents of a variable in a readable format.


d($user);

dd(...)

Debug and terminate execution. This helper prints the variable and immediately stops the script.


dd($users);

version()

Returns the current SigmaPHP framework version.


echo version();

container()

Access the service container or retrieve a specific service from it.


$router = container('query_builder');

env()

Retrieve environment variables defined in the application's environment configuration.


$env = env('APP_ENV', 'production');

config()

Retrieve configuration values from the application's configuration files.


$timezone = config('app.name');

root_path()

Generate an absolute path relative to the root directory of the application.


$logs = root_path('storage/logs');

url()

Generate a URL for a named route with optional parameters.


$url = url('user.profile', ['id' => 5]);

baseUrl()

Return the base URL of the current application.


echo baseUrl();

encrypt()

Encrypt a string using the application secret key defined in the environment configuration.


$token = encrypt('user-id-15');

decrypt()

Decrypt a previously encrypted string using the same application secret key.


$id = decrypt($token);

shareTemplateVariable()

Share variables globally across all templates so they can be accessed in any view.


shareTemplateVariable(['siteName' => 'SigmaPHP']);

defineCustomTemplateDirective()

Register a custom directive that can be used inside the template engine.


defineCustomTemplateDirective('upper', fn($text) => strtoupper($text));
Back to top