URL & Asset Helper
The URL & Asset Helper provides functions to handle URLs, redirects, asset inclusion, and active state management in LavaLust applications.
Function Summary
Function |
Description |
|---|---|
|
Returns the base URL of the application. |
|
Generates a full site URL including optional index page. |
|
Redirects to the specified URI using HTTP headers. |
|
Loads one or multiple JavaScript files from the public directory. |
|
Loads one or multiple CSS files from the public directory. |
|
Prints a CSS class if the current URL matches the specified page. |
|
Retrieves a specific URI segment. |
Available Functions
- base_url()
Returns the base URL of the application.
- Returns:
string — Base URL.
- site_url(string $url = '')
Generates a full URL to a site resource, optionally including the index page.
- Parameters:
$url (
string) – The URI segment to append.
- Returns:
string — Full URL.
- redirect(string $uri = '', bool $permanent = false, bool $exit = true)
Redirects to a given URI using HTTP headers.
- Parameters:
$uri (
string) – Destination URI.$permanent (
bool) – Whether to use 301 Permanent Redirect (default false).$exit (
bool) – Whether to exit after redirect (default true).
- Returns:
void
- load_js(array $paths)
Loads one or more JavaScript files from the public directory.
- Parameters:
$paths (
array) – List of JS file paths relative to the public directory.
- Returns:
void
- load_css(array $paths)
Loads one or more CSS files from the public directory.
- Parameters:
$paths (
array) – List of CSS file paths relative to the public directory.
- Returns:
void
- active(string $current_page, string $css_class = 'active')
Prints a CSS class if the current URL matches the specified page.
- Parameters:
$current_page (
string) – Page or route to compare with the current URI.$css_class (
string) – CSS class to output if active (default ‘active’).
- Returns:
void
- segment(int $seg)
Retrieves a specific URI segment.
- Parameters:
$seg (
int) – The segment index to retrieve.
- Returns:
string|false — Segment string if exists, false otherwise.