Framework Docs URL Helpers

URL Helpers

The Url class collects every URL-related utility: redirects, canonical URL generation, SEO slug creation, breadcrumb rendering, and request-info helpers.

Namespace: Wojo\Core\Url

Navigation

Method Signature Description
url() static url(string $path = '', array $pars = []): string Build a full URL from a path and optional query params
redirect() static redirect(string $url, int $statusCode = 302): void Send an HTTP redirect header and exit
currentUrl() static currentUrl(): string Return the full URL of the current request
protocol() static protocol(): string Return https:// or http:// based on server state
PHP
// Build an absolute URL
$href = Url::url('/docs/routing');                    // → https://example.com/docs/routing

// With query params
$href = Url::url('/search', ['q' => 'database', 'page' => 2]);
// → https://example.com/search?q=database&page=2

// Redirect
Url::redirect(Url::url('/login'));   // 302 by default
Url::redirect(Url::url('/gone'), 301);  // permanent

SEO & Slug

Method Signature Description
doSeo() static doSeo(string $string, int $max_len = 60): string Convert a title to a URL-safe slug (lowercase, hyphens)
parseSearchFilters() static parseSearchFilters(bool $wild = false): array Parse filter segments from the URL into an associative array
buildUrl() static buildUrl(string $key, string $value, string $option = 'add'): string Toggle, add, or remove a query parameter in the current URL
buildQuery() static buildQuery(): string Serialize current GET params back to a query string
PHP
// Create a slug
$slug = Url::doSeo('Hello World! This is a Test');  // → 'hello-world-this-is-a-test'

// Get the current page's URL segment (e.g. /posts/my-article → 'my-article')
$slug = Url::segment($this->segments, 1);

// Build a filter toggle URL (for filter bars)
$href = Url::buildUrl('status', 'active');   // adds ?status=active
$href = Url::buildUrl('status', 'active', 'remove');  // removes the param

Breadcrumbs

Method Signature Description
renderBreadcrumbs() static renderBreadcrumbs(array $crumbs, string $divider = '/'): string Render an HTML breadcrumb trail. The last item is the active (non-linked) crumb.
PHP
$crumbs = [
    'Home'  => Url::url('/'),
    'Blog'  => Url::url('/blog'),
    'Post'  => null,   // null = current page, rendered as plain text
];
echo Url::renderBreadcrumbs($crumbs, '>');
// → <nav ...><a href="...">Home</a> > <a href="...">Blog</a> > Post</nav>

Other Helpers

Method Description
getIP(): string Return the visitor's IP address (checks proxies)
segment(array $segs, int $id): string Return the Nth URL segment (0-indexed) or empty string
isActiveSegment(): bool Check if the current URL matches a given segment
setActiveAria(): string Return aria-current="page" when a segment matches (for nav accessibility)