Helper Functions
One-page cheat sheet for the global helpers registered in `src/Support/helpers.php`.
Category: Reference
Environment & config #
| Helper |
Usage |
env('APP_ENV', 'production') |
Reads from $_ENV, $_SERVER, or getenv(), with boolean/null coercion. Velvet treats anything other than production as the permissive “local” mode. |
config('cache.default') |
Pulls config values via ConfigRepository; pass an array to set overrides at runtime. |
app(Foo::class) / app() |
Resolve services or fetch the application container instance. |
Paths #
| Helper |
Returns |
base_path('themes/default') |
Project root or subpath. |
public_path('index.php'), storage_path('logs/app.log'), content_path('pages/welcome.md'), config_path('app.php') |
Convenience wrappers for common directories. |
HTTP & routing #
| Helper |
Usage |
route('docs.show', ['slug' => 'intro']) |
Generates URLs using the router’s named routes. |
redirect('/login', 302) |
Returns a Response configured for redirects. |
response('Body', 201) |
Builds a custom response on the fly. |
request() |
Lazily captures the current VelvetCMS\Http\Request. |
session('key') / session() |
Read a session value or get the session manager binding. |
view('partials/nav', [...]) |
Shortcut for $theme->view(). |
| Helper |
Details |
csrf_token() |
Generates/stores a 32-byte token in the session. |
csrf_field() |
<input type="hidden" name="_token" ...> for forms. |
method_field('PUT') |
Hidden _method field for HTTP verb spoofing. |
Utilities #
| Helper |
Purpose |
now() |
DateTimeImmutable respecting config('app.timezone'). |
slugify('Hello World!') |
Lowercase URL-friendly slugs. |
str_contains, str_starts_with, str_ends_with |
Polyfills for legacy PHP installs. |
array_get($data, 'meta.author', 'N/A') |
Dot-notation access. |
e($value) |
HTML-escape strings (used by the template engine). |
Debugging #
| Helper |
Behavior |
dump($var) |
var_dump without exit. |
dd($var) |
Dump(s) then exit. |
abort(403, 'Forbidden') |
Sends status code + message and stops execution (simple fallback when exceptions aren’t available). |
old('email') |
Retrieve _old_input for form repopulation. |
Keep this page handy when writing controllers, modules, or templates—most day-to-day tasks can be handled with these helpers without manually poking the container.