-
Notifications
You must be signed in to change notification settings - Fork 0
Global Helpers
Technomantus Corvi edited this page Sep 5, 2026
·
1 revision
| Function | Description |
|---|---|
e($value) |
Escapes HTML to prevent XSS |
env($key, $default) |
Reads a variable from .env
|
view($name, $data) |
Renders a view inside the layout |
url($path) |
Absolute URL: url('/about') → http://localhost:8050/about
|
redirect($path) |
Redirects and stops execution |
current_uri() |
Current normalized path (single source of truth for router + views) |
session_ensure() |
Starts the session if not already started |
flash($key) |
Reads and clears a flash message |
old($key, $default) |
Retrieves a previous input value (for re-populating forms) |
keep_old($data) |
Saves data to the session so old() can retrieve it after a redirect |
format_date($datetime) |
Formats a date according to the active locale (en → m/d/Y, es → d/m/Y) |
t($key, $replace = []) |
Translates a dot-notation key — see Internationalization |
current_locale() |
Active locale: session override if set, otherwise APP_LOCALE from .env
|
locale_switch_url($code) |
Builds the URL for switching to a given language, preserving the current path |
accepted_locales() |
List of enabled language codes from ACCEPTED_LANGUAGES, or empty if unset |
locale_switcher_enabled() |
true if the language switcher should be shown at all |
csrf_field() |
Renders a hidden <input> with the current CSRF token |
csrf_verify($token) |
Timing-safe verification of a submitted CSRF token |
| Function | Description |
|---|---|
auth_check() |
true if a user is currently logged in |
auth_user() |
The logged-in user's record, or null
|
auth_login($user) |
Logs a user in (regenerates the session ID) |
auth_logout() |
Logs the current user out |
auth_require() |
Redirects to /login if not authenticated; call as the first line of a protected controller method |
Mail::send($to, $subject, $htmlBody); // → boolThin wrapper around PHPMailer, same lazy-connect pattern as Database/Redis/Mongo — nothing connects to SMTP until send() is called.