system/helpersurl_helper.php

CodeIgniter

An open source application development framework for PHP

This content is released under the MIT License (MIT)

Copyright (c) 2014 - 2016, British Columbia Institute of Technology

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

site_url()

site_url(string  $uri = '', string  $protocol = NULL) : string

Site URL

Create a local URL based on your basepath. Segments can be passed via the first parameter either as a string or an array.

Parameters

string $uri
string $protocol

Returns

string

base_url()

base_url(string  $uri = '', string  $protocol = NULL) : string

Base URL

Create a local URL based on your basepath. Segments can be passed in as a string or an array, same as site_url or a URL to a file can be passed in, e.g. to an image file.

Parameters

string $uri
string $protocol

Returns

string

current_url()

current_url() : string

Current URL

Returns the full URL (including segments) of the page where this function is placed

Returns

string

uri_string()

uri_string() : string

URL String

Returns the URI segments.

Returns

string

index_page()

index_page() : string

Index page

Returns the "index_page" from your config file

Returns

string

anchor()

anchor(  $uri = '',   $title = '',   $attributes = '') : string

Anchor Link

Creates an anchor based on the local URL.

Parameters

$uri
$title
$attributes

Returns

string

anchor_popup()

anchor_popup(  $uri = '',   $title = '',   $attributes = FALSE) : string

Anchor Link - Pop-up version

Creates an anchor based on the local URL. The link opens a new window based on the attributes specified.

Parameters

$uri
$title
$attributes

Returns

string

mailto()

mailto(  $email,   $title = '',   $attributes = '') : string

Mailto Link

Parameters

$email
$title
$attributes

Returns

string

safe_mailto()

safe_mailto(  $email,   $title = '',   $attributes = '') : string

Encoded Mailto Link

Create a spam-protected mailto link written in Javascript

Parameters

$email
$title
$attributes

Returns

string

auto_link()

auto_link(  $str,   $type = 'both',   $popup = FALSE) : string

Auto-linker

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
$type
$popup

Returns

string

prep_url()

prep_url(  $str = '') : string

Prep URL

Simply adds the http:// part if no scheme is included

Parameters

$str

Returns

string

url_title()

url_title(string  $str, string  $separator = '-', boolean  $lowercase = FALSE) : string

Create URL Title

Takes a "title" string as input and creates a human-friendly URL string with a "separator" string as the word separator.

Parameters

string $str

Input string

string $separator

Word separator (usually '-' or '_')

boolean $lowercase

Whether to transform the output string to lowercase

Returns

string

redirect()

redirect(string  $uri = '', string  $method = 'auto', integer  $code = NULL) : void

Header Redirect

Header redirect in two flavors For very fine grained control over headers, you could use the Output Library's set_header() function.

Parameters

string $uri

URL

string $method

Redirect method 'auto', 'location' or 'refresh'

integer $code

HTTP Response status code