url_helper.php
This file is part of the CodeIgniter 4 framework.
(c) CodeIgniter Foundation admin@codeigniter.com
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
Table of Contents
- site_url() : string
- Returns a site URL as defined by the App config.
- base_url() : string
- Returns the base URL as defined by the App config.
- current_url() : string|URI
- Returns the current full URL based on the IncomingRequest.
- previous_url() : URI|mixed|string
- Returns the previous URL the current visitor was on. For security reasons we first check in a saved session variable, if it exists, and use that.
- uri_string() : string
- URL String
- index_page() : string
- Index page
- anchor() : string
- Anchor Link
- anchor_popup() : string
- Anchor Link - Pop-up version
- mailto() : string
- Mailto Link
- safe_mailto() : string
- Encoded Mailto Link
- auto_link() : string
- Auto-linker
- prep_url() : string
- Prep URL - Simply adds the http:// or https:// part if no scheme is included.
- url_title() : string
- Create URL Title
- mb_url_title() : string
- Create URL Title that takes into account accented characters
- url_to() : string
- Get the full, absolute URL to a controller method (with additional arguments)
- url_is() : bool
- Determines if current url path contains the given path. It may contain a wildcard (*) which will allow any valid character.
Functions
site_url()
Returns a site URL as defined by the App config.
site_url([mixed $relativePath = '' ][, string|null $scheme = null ][, App|null $config = null ]) : string
Parameters
- $relativePath : mixed = ''
-
URI string or array of URI segments
- $scheme : string|null = null
- $config : App|null = null
-
Alternate configuration to use
Return values
string —base_url()
Returns the base URL as defined by the App config.
base_url([mixed $relativePath = '' ][, string $scheme = null ]) : string
Base URLs are trimmed site URLs without the index page.
Parameters
- $relativePath : mixed = ''
-
URI string or array of URI segments
- $scheme : string = null
Return values
string —current_url()
Returns the current full URL based on the IncomingRequest.
current_url([bool $returnObject = false ][, IncomingRequest|null $request = null ]) : string|URI
String returns ignore query and fragment parts.
Parameters
- $returnObject : bool = false
-
True to return an object instead of a string
- $request : IncomingRequest|null = null
-
A request to use when retrieving the path
Return values
string|URI —previous_url()
Returns the previous URL the current visitor was on. For security reasons we first check in a saved session variable, if it exists, and use that.
previous_url([bool $returnObject = false ]) : URI|mixed|string
If that's not available, however, we'll use a sanitized url from $_SERVER['HTTP_REFERER'] which can be set by the user so is untrusted and not set by certain browsers/servers.
Parameters
- $returnObject : bool = false
Return values
URI|mixed|string —uri_string()
URL String
uri_string([bool $relative = false ]) : string
Returns the path part of the current URL
Parameters
- $relative : bool = false
-
Whether the resulting path should be relative to baseURL
Return values
string —index_page()
Index page
index_page([App|null $altConfig = null ]) : string
Returns the "index_page" from your config file
Parameters
- $altConfig : App|null = null
-
Alternate configuration to use
Return values
string —anchor()
Anchor Link
anchor([mixed $uri = '' ][, string $title = '' ][, mixed $attributes = '' ][, App|null $altConfig = null ]) : string
Creates an anchor based on the local URL.
Parameters
- $uri : mixed = ''
-
URI string or array of URI segments
- $title : string = ''
-
The link title
- $attributes : mixed = ''
-
Any attributes
- $altConfig : App|null = null
-
Alternate configuration to use
Return values
string —anchor_popup()
Anchor Link - Pop-up version
anchor_popup([string $uri = '' ][, string $title = '' ][, mixed $attributes = false ][, App|null $altConfig = null ]) : string
Creates an anchor based on the local URL. The link opens a new window based on the attributes specified.
Parameters
- $uri : string = ''
-
the URL
- $title : string = ''
-
the link title
- $attributes : mixed = false
-
any attributes
- $altConfig : App|null = null
-
Alternate configuration to use
Return values
string —mailto()
Mailto Link
mailto(string $email[, string $title = '' ][, mixed $attributes = '' ]) : string
Parameters
- $email : string
-
the email address
- $title : string = ''
-
the link title
- $attributes : mixed = ''
-
any attributes
Return values
string —safe_mailto()
Encoded Mailto Link
safe_mailto(string $email[, string $title = '' ][, mixed $attributes = '' ]) : string
Create a spam-protected mailto link written in Javascript
Parameters
- $email : string
-
the email address
- $title : string = ''
-
the link title
- $attributes : mixed = ''
-
any attributes
Return values
string —auto_link()
Auto-linker
auto_link(string $str[, string $type = 'both' ][, bool $popup = false ]) : string
Automatically links URL and Email addresses. Note: There's a bit of extra code here to deal with URLs or emails that end in a period. We'll strip these off and add them after the link.
Parameters
- $str : string
-
the string
- $type : string = 'both'
-
the type: email, url, or both
- $popup : bool = false
-
whether to create pop-up links
Return values
string —prep_url()
Prep URL - Simply adds the http:// or https:// part if no scheme is included.
prep_url([string $str = '' ][, bool $secure = false ]) : string
Formerly used URI, but that does not play nicely with URIs missing the scheme.
Parameters
- $str : string = ''
-
the URL
- $secure : bool = false
-
set true if you want to force https://
Return values
string —url_title()
Create URL Title
url_title(string $str[, string $separator = '-' ][, bool $lowercase = false ]) : string
Takes a "title" string as input and creates a human-friendly URL string with a "separator" string as the word separator.
Parameters
- $str : string
-
Input string
- $separator : string = '-'
-
Word separator (usually '-' or '_')
- $lowercase : bool = false
-
Whether to transform the output string to lowercase
Return values
string —mb_url_title()
Create URL Title that takes into account accented characters
mb_url_title(string $str[, string $separator = '-' ][, bool $lowercase = false ]) : string
Takes a "title" string as input and creates a human-friendly URL string with a "separator" string as the word separator.
Parameters
- $str : string
-
Input string
- $separator : string = '-'
-
Word separator (usually '-' or '_')
- $lowercase : bool = false
-
Whether to transform the output string to lowercase
Return values
string —url_to()
Get the full, absolute URL to a controller method (with additional arguments)
url_to(string $controller, mixed ...$args) : string
Parameters
- $controller : string
- $args : mixed
Tags
Return values
string —url_is()
Determines if current url path contains the given path. It may contain a wildcard (*) which will allow any valid character.
url_is(string $path) : bool
Example: if (url_is('admin*)) ...
Parameters
- $path : string