Kohana 3.1.2 (Hirondelle) CheatSheet

Designation: <item> — static property/method; # <item> — protected property/method

arr  ? 
close

Array helper.

properties
delimiter
close

Arr::delimiter

default delimiter for path()

methods
callback
close

Arr::callback(string $str)

Creates a callable function and parameter list from a string representation. Note that this function does not validate the callback string.

// Get the callback function and parameters
list($func, $params) = Arr::callback('Foo::bar(apple,orange)');

// Get the result of the callback
$result = call_user_func_array($func, $params);
extract
close

Arr::extract(array $array, array $keys, mixed $default = NULL)

Retrieves multiple keys from an array. If the key does not exist in the array, the default value will be added instead.

// Get the values "username", "password" from $_POST
$auth = Arr::extract($_POST, array('username', 'password'));
flatten
close

Arr::flatten(array $array)

Convert a multi-dimensional array into a single-dimensional array.

$array = array('set' => array('one' => 'something'), 'two' => 'other');

// Flatten the array
$array = Arr::flatten($array);

// The array will now be
array('one' => 'something', 'two' => 'other');

The keys of array values will be discarded.

get
close

Arr::get(array $array, string $key, mixed $default = NULL)

Retrieve a single key from an array. If the key does not exist in the array, the default value will be returned instead.

// Get the value "username" from $_POST, if it exists
$username = Arr::get($_POST, 'username');

// Get the value "sorting" from $_GET, if it exists
$sorting = Arr::get($_GET, 'sorting');
is_array
close

Arr::is_array(mixed $value)

Test if a value is an array with an additional check for array-like objects.

// Returns TRUE
Arr::is_array(array());
Arr::is_array(new ArrayObject);

// Returns FALSE
Arr::is_array(FALSE);
Arr::is_array('not an array!');
Arr::is_array(Database::instance());
is_assoc
close

Arr::is_assoc(array $array)

Tests if an array is associative or not.

// Returns TRUE
Arr::is_assoc(array('username' => 'john.doe'));

// Returns FALSE
Arr::is_assoc('foo', 'bar');
map
close

Arr::map(mixed $callback, array $array)

Recursive version of array_map, applies the same callback to all elements in an array, including sub-arrays.

// Apply "strip_tags" to every element in the array
$array = Arr::map('strip_tags', $array);

Unlike array_map, this method requires a callback and will only map a single array.

merge
close

Arr::merge(array $a1, array $a2)

Merges one or more arrays recursively and preserves all keys. Note that this does not work the same as array_merge_recursive!

$john = array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane'));
$mary = array('name' => 'mary', 'children' => array('jane'));

// John and Mary are married, merge them together
$john = Arr::merge($john, $mary);

// The output of $john will now be:
array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane'))
overwrite
close

Arr::overwrite(array $array1, array $array2)

Overwrites an array with values from input arrays. Keys that do not exist in the first array will not be added!

$a1 = array('name' => 'john', 'mood' => 'happy', 'food' => 'bacon');
$a2 = array('name' => 'jack', 'food' => 'tacos', 'drink' => 'beer');

// Overwrite the values of $a1 with $a2
$array = Arr::overwrite($a1, $a2);

// The output of $array will now be:
array('name' => 'jack', 'mood' => 'happy', 'food' => 'tacos')
path
close

Arr::path(array $array, mixed $path, mixed $default = NULL, string $delimiter = NULL)

Gets a value from an array using a dot separated path.

// Get the value of $array['foo']['bar']
$value = Arr::path($array, 'foo.bar');

Using a wildcard "*" will search intermediate arrays and return an array.

// Get the values of "color" in theme
$colors = Arr::path($array, 'theme.*.color');

// Using an array of keys
$colors = Arr::path($array, array('theme', '*', 'color'));
pluck
close

Arr::pluck(array $array, string $key)

Retrieves muliple single-key values from a list of arrays.

// Get all of the "id" values from a result
$ids = Arr::pluck($result, 'id');

A list of arrays is an array that contains arrays, eg: array(array $a, array $b, array $c, ...)

range
close

Arr::range(integer $step = integer 10, integer $max = integer 100)

Fill an array with a range of numbers.

// Fill an array with values 5, 10, 15, 20
$values = Arr::range(5, 20);
set_path
close

Arr::set_path(array $array, string $path, mixed $value, string $delimiter = NULL)

Set a value on an array by path.

unshift
close

Arr::unshift(array $array, string $key, mixed $val)

Adds a value to the beginning of an associative array.

// Add an empty value to the start of a select list
Arr::unshift($array, 'none', 'Select a value');
cli  ? 
close

Helper functions for working in a command-line environment.

methods
options
close

CLI::options(string $options)

Returns one or more command-line options. Options are specified using standard CLI syntax:

php index.php --username=john.smith --password=secret --var="some value with spaces"

// Get the values of "username" and "password"
$auth = CLI::options('username', 'password');
config_file  ? 
close

File-based configuration reader. Multiple configuration directories can be used by attaching multiple instances of this class to Config.

properties
# _configuration_group
close

Config_File::_configuration_group

Configuration group name

# _configuration_modified
close

Config_File::_configuration_modified

Has the config group changed?

methods
append
close

Config_File::append()

append
close

Config_File::append()

as_array
close

Config_File::as_array()

Return the raw array that is being used for this object.

$array = $config->as_array();
asort
close

Config_File::asort()

asort
close

Config_File::asort()

count
close

Config_File::count()

count
close

Config_File::count()

exchangeArray
close

Config_File::exchangeArray()

exchangeArray
close

Config_File::exchangeArray()

get
close

Config_File::get(string $key, mixed $default = NULL)

Get a variable from the configuration or return the default value.

$value = $config->get($key);
getArrayCopy
close

Config_File::getArrayCopy()

getArrayCopy
close

Config_File::getArrayCopy()

getFlags
close

Config_File::getFlags()

getFlags
close

Config_File::getFlags()

getIterator
close

Config_File::getIterator()

getIterator
close

Config_File::getIterator()

getIteratorClass
close

Config_File::getIteratorClass()

getIteratorClass
close

Config_File::getIteratorClass()

ksort
close

Config_File::ksort()

ksort
close

Config_File::ksort()

load
close

Config_File::load(string $group, array $config = NULL)

Load and merge all of the configuration files in this group.

$config->load($name);
natcasesort
close

Config_File::natcasesort()

natcasesort
close

Config_File::natcasesort()

natsort
close

Config_File::natsort()

natsort
close

Config_File::natsort()

offsetExists
close

Config_File::offsetExists()

offsetExists
close

Config_File::offsetExists()

offsetGet
close

Config_File::offsetGet()

offsetGet
close

Config_File::offsetGet()

offsetSet
close

Config_File::offsetSet()

offsetSet
close

Config_File::offsetSet()

offsetUnset
close

Config_File::offsetUnset()

offsetUnset
close

Config_File::offsetUnset()

set
close

Config_File::set(string $key, mixed $value)

Sets a value in the configuration array.

$config->set($key, $new_value);
setFlags
close

Config_File::setFlags()

setFlags
close

Config_File::setFlags()

setIteratorClass
close

Config_File::setIteratorClass()

setIteratorClass
close

Config_File::setIteratorClass()

uasort
close

Config_File::uasort()

uasort
close

Config_File::uasort()

uksort
close

Config_File::uksort()

uksort
close

Config_File::uksort()

config_reader  ? 
close

Abstract configuration reader. All configuration readers must extend this class.

properties
# _configuration_group
close

Config_Reader::_configuration_group

Configuration group name

methods
append
close

Config_Reader::append()

append
close

Config_Reader::append()

as_array
close

Config_Reader::as_array()

Return the raw array that is being used for this object.

$array = $config->as_array();
asort
close

Config_Reader::asort()

asort
close

Config_Reader::asort()

count
close

Config_Reader::count()

count
close

Config_Reader::count()

exchangeArray
close

Config_Reader::exchangeArray()

exchangeArray
close

Config_Reader::exchangeArray()

get
close

Config_Reader::get(string $key, mixed $default = NULL)

Get a variable from the configuration or return the default value.

$value = $config->get($key);
getArrayCopy
close

Config_Reader::getArrayCopy()

getArrayCopy
close

Config_Reader::getArrayCopy()

getFlags
close

Config_Reader::getFlags()

getFlags
close

Config_Reader::getFlags()

getIterator
close

Config_Reader::getIterator()

getIterator
close

Config_Reader::getIterator()

getIteratorClass
close

Config_Reader::getIteratorClass()

getIteratorClass
close

Config_Reader::getIteratorClass()

ksort
close

Config_Reader::ksort()

ksort
close

Config_Reader::ksort()

load
close

Config_Reader::load(string $group, array $config = NULL)

Loads a configuration group.

$config->load($name, $array);

This method must be extended by all readers. After the group has been loaded, call parent::load($group, $config) for final preparation.

natcasesort
close

Config_Reader::natcasesort()

natcasesort
close

Config_Reader::natcasesort()

natsort
close

Config_Reader::natsort()

natsort
close

Config_Reader::natsort()

offsetExists
close

Config_Reader::offsetExists()

offsetExists
close

Config_Reader::offsetExists()

offsetGet
close

Config_Reader::offsetGet()

offsetGet
close

Config_Reader::offsetGet()

offsetSet
close

Config_Reader::offsetSet()

offsetSet
close

Config_Reader::offsetSet()

offsetUnset
close

Config_Reader::offsetUnset()

offsetUnset
close

Config_Reader::offsetUnset()

set
close

Config_Reader::set(string $key, mixed $value)

Sets a value in the configuration array.

$config->set($key, $new_value);
setFlags
close

Config_Reader::setFlags()

setFlags
close

Config_Reader::setFlags()

setIteratorClass
close

Config_Reader::setIteratorClass()

setIteratorClass
close

Config_Reader::setIteratorClass()

uasort
close

Config_Reader::uasort()

uasort
close

Config_Reader::uasort()

uksort
close

Config_Reader::uksort()

uksort
close

Config_Reader::uksort()

config  ? 
close

Wrapper for configuration arrays. Multiple configuration readers can be attached to allow loading configuration from files, database, etc.

properties
# _instance
close

Config::_instance

Singleton static instance

# _readers
close

Config::_readers

Configuration readers

methods
attach
close

Config::attach(object $reader, boolean $first = bool TRUE)

Attach a configuration reader. By default, the reader will be added as the first used reader. However, if the reader should be used only when all other readers fail, use FALSE for the second parameter.

$config->attach($reader);        // Try first
$config->attach($reader, FALSE); // Try last
copy
close

Config::copy(string $group)

Copy one configuration group to all of the other readers.

$config->copy($name);
detach
close

Config::detach(object $reader)

Detach a configuration reader.

$config->detach($reader);
instance
close

Config::instance()

Get the singleton instance of Config.

$config = Config::instance();
load
close

Config::load(string $group)

Load a configuration group. Searches the readers in order until the group is found. If the group does not exist, an empty configuration array will be loaded using the first reader.

$array = $config->load($name);
cookie  ? 
close

Cookie helper.

properties
domain
close

Cookie::domain

Restrict the domain that the cookie is available to

expiration
close

Cookie::expiration

Number of seconds before the cookie expires

httponly
close

Cookie::httponly

Only transmit cookies over HTTP, disabling Javascript access

path
close

Cookie::path

Restrict the path that the cookie is available to

salt
close

Cookie::salt

Magic salt to add to the cookie

secure
close

Cookie::secure

Only transmit cookies over secure connections

methods
delete
close

Cookie::delete(string $name)

Deletes a cookie by making the value NULL and expiring it.

Cookie::delete('theme');
get
close

Cookie::get(string $key, mixed $default = NULL)

Gets the value of a signed cookie. Cookies without signatures will not be returned. If the cookie signature is present, but invalid, the cookie will be deleted.

// Get the "theme" cookie, or use "blue" if the cookie does not exist
$theme = Cookie::get('theme', 'blue');
salt
close

Cookie::salt(string $name, string $value)

Generates a salt string for a cookie based on the name and value.

$salt = Cookie::salt('theme', 'red');
set
close

Cookie::set(string $name, string $value, integer $expiration = NULL)

Sets a signed cookie. Note that all cookie values must be strings and no automatic serialization will be performed!

// Set the "theme" cookie
Cookie::set('theme', 'red');
date  ? 
close

Date helper.

properties
timestamp_format
close

Date::timestamp_format

Default timestamp format for formatted_time

timezone
close

Date::timezone

Timezone for formatted_time

methods
adjust
close

Date::adjust(integer $hour, string $ampm)

Adjusts a non-24-hour number into a 24-hour number.

$hour = Date::adjust(3, 'pm'); // 15
ampm
close

Date::ampm(integer $hour)

Returns AM or PM, based on a given hour (in 24 hour format).

$type = Date::ampm(12); // PM
$type = Date::ampm(1);  // AM
days
close

Date::days(integer $month, integer $year = bool FALSE)

Number of days in a given month and year. Typically used as a shortcut for generating a list that can be used in a form.

Date::days(4, 2010); // 1, 2, 3, ..., 28, 29, 30
dos2unix
close

Date::dos2unix(integer $timestamp = bool FALSE)

Converts a DOS timestamp to UNIX format.There are very few cases where this is needed, but some binary formats use it (eg: zip files.) Converting the other direction is done using {@link Date::unix2dos}.

$unix = Date::dos2unix($dos);
formatted_time
close

Date::formatted_time(string $datetime_str = string(3) "now", string $timestamp_format = NULL, $timezone = NULL)

Returns a date/time string with the specified timestamp format

$time = Date::formatted_time('5 minutes ago');
fuzzy_span
close

Date::fuzzy_span(integer $timestamp, integer $local_timestamp = NULL)

Returns the difference between a time and now in a "fuzzy" way. Displaying a fuzzy time instead of a date is usually faster to read and understand.

$span = Date::fuzzy_span(time() - 10); // "moments ago"
$span = Date::fuzzy_span(time() + 20); // "in moments"

A second parameter is available to manually set the "local" timestamp, however this parameter shouldn't be needed in normal usage and is only included for unit tests

hours
close

Date::hours(integer $step = integer 1, boolean $long = bool FALSE, integer $start = NULL)

Number of hours in a day. Typically used as a shortcut for generating a list that can be used in a form.

$hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12
minutes
close

Date::minutes(integer $step = integer 5)

Number of minutes in an hour, incrementing by a step. Typically used as a shortcut for generating a list that can be used in a form.

$minutes = Date::minutes(); // 05, 10, 15, ..., 50, 55, 60
months
close

Date::months(string $format = NULL)

Number of months in a year. Typically used as a shortcut for generating a list that can be used in a form.

By default a mirrored array of $month_number => $month_number is returned

Date::months();
// aray(1 => 1, 2 => 2, 3 => 3, ..., 12 => 12)

But you can customise this by passing in either Date::MONTHS_LONG

Date::months(Date::MONTHS_LONG);
// array(1 => 'January', 2 => 'February', ..., 12 => 'December')

Or Date::MONTHS_SHORT

Date::months(Date::MONTHS_SHORT);
// array(1 => 'Jan', 2 => 'Feb', ..., 12 => 'Dec')
offset
close

Date::offset(string $remote, string $local = NULL, mixed $now = NULL)

Returns the offset (in seconds) between two time zones. Use this to display dates to users in different time zones.

$seconds = Date::offset('America/Chicago', 'GMT');

A list of time zones that PHP supports can be found at http://php.net/timezones.

seconds
close

Date::seconds(integer $step = integer 1, integer $start = integer 0, integer $end = integer 60)

Number of seconds in a minute, incrementing by a step. Typically used as a shortcut for generating a list that can used in a form.

$seconds = Date::seconds(); // 01, 02, 03, ..., 58, 59, 60
span
close

Date::span(integer $remote, integer $local = NULL, string $output = string(45) "years,months,weeks,days,hours,minutes,seconds")

Returns time difference between two timestamps, in human readable format. If the second timestamp is not given, the current time will be used. Also consider using Date::fuzzy_span when displaying a span.

$span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2)
$span = Date::span(60, 182, 'minutes'); // 2
unix2dos
close

Date::unix2dos(integer $timestamp = bool FALSE)

Converts a UNIX timestamp to DOS format. There are very few cases where this is needed, but some binary formats use it (eg: zip files.) Converting the other direction is done using {@link Date::dos2unix}.

$dos = Date::unix2dos($unix);
years
close

Date::years(integer $start = bool FALSE, integer $end = bool FALSE)

Returns an array of years between a starting and ending year. By default, the the current year - 5 and current year + 5 will be used. Typically used as a shortcut for generating a list that can be used in a form.

$years = Date::years(2000, 2010); // 2000, 2001, ..., 2009, 2010
debug  ? 
close

Contains debugging and dumping tools.

methods
dump
close

Debug::dump(mixed $value, integer $length = integer 128)

Returns an HTML string of information about a single variable.

Borrows heavily on concepts from the Debug class of Nette.

path
close

Debug::path(string $file)

Removes application, system, modpath, or docroot from a filename, replacing them with the plain text equivalents. Useful for debugging when you want to display a shorter path.

// Displays SYSPATH/classes/kohana.php
echo Debug::path(Kohana::find_file('classes', 'kohana'));
source
close

Debug::source(string $file, integer $line_number, integer $padding = integer 5)

Returns an HTML string, highlighting a specific line of a file, with some number of lines padded above and below.

// Highlights the current line of the current file
echo Debug::source(__FILE__, __LINE__);
trace
close

Debug::trace(string $trace = NULL)

Returns an array of HTML strings that represent each step in the backtrace.

// Displays the entire current backtrace
echo implode('<br/>', Debug::trace());
vars
close

Debug::vars()

Returns an HTML string of debugging information about any number of variables, each wrapped in a "pre" tag:

// Displays the type and value of each variable
echo Debug::vars($foo, $bar, $baz);
# _dump
close

Debug::_dump(mixed $var, integer $length = integer 128, integer $level = integer 0)

Helper for Debug::dump(), handles recursion in arrays and objects.

encrypt  ? 
close

The Encrypt library provides two-way encryption of text and binary strings using the Mcrypt extension, which consists of three parts: the key, the cipher, and the mode.

The Key
A secret passphrase that is used for encoding and decoding
The Cipher
A cipher determines how the encryption is mathematically calculated. By default, the "rijndael-128" cipher is used. This is commonly known as "AES-128" and is an industry standard.
The Mode
The mode determines how the encrypted data is written in binary form. By default, the "nofb" mode is used, which produces short output with high entropy.
properties
default
close

Encrypt::default

default instance name

instances
close

Encrypt::instances

Encrypt class instances

# _rand
close

Encrypt::_rand

OS-dependent RAND type to use

methods
decode
close

Encrypt::decode(string $data)

Decrypts an encoded string back to its original value.

$data = $encrypt->decode($data);
encode
close

Encrypt::encode(string $data)

Encrypts a string and returns an encrypted string that can be decoded.

$data = $encrypt->encode($data);

The encrypted binary data is encoded using base64 to convert it to a string. This string can be stored in a database, displayed, and passed using most other means without corruption.

instance
close

Encrypt::instance(string $name = NULL)

Returns a singleton instance of Encrypt. An encryption key must be provided in your "encrypt" configuration file.

$encrypt = Encrypt::instance();
feed  ? 
close

RSS and Atom feed helper.

methods
create
close

Feed::create(array $info, array $items, string $format = string(4) "rss2", string $encoding = string(5) "UTF-8")

Creates a feed from the given parameters.

parse
close

Feed::parse(string $feed, integer $limit = integer 0)

Parses a remote feed into an array.

file  ? 
close

File helper class.

methods
ext_by_mime
close

File::ext_by_mime(string $type)

Lookup a single file extension by MIME type.

exts_by_mime
close

File::exts_by_mime(string $type)

Lookup file extensions by MIME type

join
close

File::join(string $filename)

Join a split file into a whole file. Does the reverse of File::split.

$count = File::join($file);
mime
close

File::mime(string $filename)

Attempt to get the mime type from a file. This method is horribly unreliable, due to PHP being horribly unreliable when it comes to determining the mime type of a file.

$mime = File::mime($file);
mime_by_ext
close

File::mime_by_ext(string $extension)

Return the mime type of an extension.

$mime = File::mime_by_ext('png'); // "image/png"
mimes_by_ext
close

File::mimes_by_ext(string $extension)

Lookup MIME types for a file

split
close

File::split(string $filename, string $piece_size = integer 10)

Split a file into pieces matching a specific size. Used when you need to split large files into smaller pieces for easy transmission.

$count = File::split($file);
form  ? 
close

Form helper class. Unless otherwise noted, all generated HTML will be made safe using the HTML::chars method. This prevents against simple XSS attacks that could otherwise be trigged by inserting HTML characters into form fields.

methods
button
close

Form::button(string $name, string $body, array $attributes = NULL)

Creates a button form input. Note that the body of a button is NOT escaped, to allow images and other HTML to be used.

echo Form::button('save', 'Save Profile', array('type' => 'submit'));
checkbox
close

Form::checkbox(string $name, string $value = NULL, boolean $checked = bool FALSE, array $attributes = NULL)

Creates a checkbox form input.

echo Form::checkbox('remember_me', 1, (bool) $remember);
close
close

Form::close()

Creates the closing form tag.

echo Form::close();
file
close

Form::file(string $name, array $attributes = NULL)

Creates a file upload form input. No input value can be specified.

echo Form::file('image');
hidden
close

Form::hidden(string $name, string $value = NULL, array $attributes = NULL)

Creates a hidden form input.

echo Form::hidden('csrf', $token);
image
close

Form::image(string $name, string $value, array $attributes = NULL, boolean $index = bool FALSE)

Creates a image form input.

echo Form::image(NULL, NULL, array('src' => 'media/img/login.png'));
input
close

Form::input(string $name, string $value = NULL, array $attributes = NULL)

Creates a form input. If no type is specified, a "text" type input will be returned.

echo Form::input('username', $username);
label
close

Form::label(string $input, string $text = NULL, array $attributes = NULL)

Creates a form label. Label text is not automatically translated.

echo Form::label('username', 'Username');
open
close

Form::open(mixed $action = NULL, array $attributes = NULL)

Generates an opening HTML form tag.

// Form will submit back to the current page using POST
echo Form::open();

// Form will submit to 'search' using GET
echo Form::open('search', array('method' => 'get'));

// When "file" inputs are present, you must include the "enctype"
echo Form::open(NULL, array('enctype' => 'multipart/form-data'));
password
close

Form::password(string $name, string $value = NULL, array $attributes = NULL)

Creates a password form input.

echo Form::password('password');
radio
close

Form::radio(string $name, string $value = NULL, boolean $checked = bool FALSE, array $attributes = NULL)

Creates a radio form input.

echo Form::radio('like_cats', 1, $cats);
echo Form::radio('like_cats', 0, ! $cats);
select
close

Form::select(string $name, array $options = NULL, mixed $selected = NULL, array $attributes = NULL)

Creates a select form input.

echo Form::select('country', $countries, $country);

Support for multiple selected options was added in v3.0.7.

submit
close

Form::submit(string $name, string $value, array $attributes = NULL)

Creates a submit form input.

echo Form::submit(NULL, 'Login');
textarea
close

Form::textarea(string $name, string $body = string(0) "", array $attributes = NULL, boolean $double_encode = bool TRUE)

Creates a textarea form input.

echo Form::textarea('about', $about);
fragment  ? 
close

View fragment caching. This is primarily used to cache small parts of a view that rarely change. For instance, you may want to cache the footer of your template because it has very little dynamic content. Or you could cache a user profile page and delete the fragment when the user updates.

For obvious reasons, fragment caching should not be applied to any content that contains forms.

Multiple language (I18n) support was added in v3.0.4.

properties
i18n
close

Fragment::i18n

use multilingual fragment support?

lifetime
close

Fragment::lifetime

default number of seconds to cache for

# _caches
close

Fragment::_caches

list of buffer => cache key

methods
delete
close

Fragment::delete(string $name, boolean $i18n = NULL)

Delete a cached fragment.

Fragment::delete($key);
load
close

Fragment::load(string $name, integer $lifetime = NULL, boolean $i18n = NULL)

Load a fragment from cache and display it. Multiple fragments can be nested with different life times.

if ( ! Fragment::load('footer')) {
    // Anything that is echo'ed here will be saved
    Fragment::save();
}
save
close

Fragment::save()

Saves the currently open fragment in the cache.

Fragment::save();
# _cache_key
close

Fragment::_cache_key(string $name, boolean $i18n = NULL)

Generate the cache key name for a fragment.

$key = Fragment::_cache_key('footer', TRUE);
html  ? 
close

HTML helper class. Provides generic methods for generating various HTML tags and making output HTML safe.

properties
attribute_order
close

HTML::attribute_order

preferred order of attributes

windowed_urls
close

HTML::windowed_urls

automatically target external URLs to a new window?

methods
anchor
close

HTML::anchor(string $uri, string $title = NULL, array $attributes = NULL, mixed $protocol = NULL, boolean $index = bool FALSE)

Create HTML link anchors. Note that the title is not escaped, to allow HTML elements within links (images, etc).

echo HTML::anchor('/user/profile', 'My Profile');
attributes
close

HTML::attributes(array $attributes = NULL)

Compiles an array of HTML attributes into an attribute string. Attributes will be sorted using HTML::$attribute_order for consistency.

echo '<div'.HTML::attributes($attrs).'>'.$content.'</div>';
chars
close

HTML::chars(string $value, boolean $double_encode = bool TRUE)

Convert special characters to HTML entities. All untrusted content should be passed through this method to prevent XSS injections.

echo HTML::chars($username);
email
close

HTML::email(string $email)

Generates an obfuscated version of an email address. Helps prevent spam robots from finding email addresses.

echo HTML::email($address);
entities
close

HTML::entities(string $value, boolean $double_encode = bool TRUE)

Convert all applicable characters to HTML entities. All characters that cannot be represented in HTML with the current character set will be converted to entities.

echo HTML::entities($username);
file_anchor
close

HTML::file_anchor(string $file, string $title = NULL, array $attributes = NULL, mixed $protocol = NULL, boolean $index = bool FALSE)

Creates an HTML anchor to a file. Note that the title is not escaped, to allow HTML elements within links (images, etc).

echo HTML::file_anchor('media/doc/user_guide.pdf', 'User Guide');
image
close

HTML::image(string $file, array $attributes = NULL, mixed $protocol = NULL, boolean $index = bool FALSE)

Creates a image link.

echo HTML::image('media/img/logo.png', array('alt' => 'My Company'));
mailto
close

HTML::mailto(string $email, string $title = NULL, array $attributes = NULL)

Creates an email (mailto:) anchor. Note that the title is not escaped, to allow HTML elements within links (images, etc).

echo HTML::mailto($address);
obfuscate
close

HTML::obfuscate(string $string)

Generates an obfuscated version of a string. Text passed through this method is less likely to be read by web crawlers and robots, which can be helpful for spam prevention, but can prevent legitimate robots from reading your content.

echo HTML::obfuscate($text);
script
close

HTML::script(string $file, array $attributes = NULL, mixed $protocol = NULL, boolean $index = bool FALSE)

Creates a script link.

echo HTML::script('media/js/jquery.min.js');
style
close

HTML::style(string $file, array $attributes = NULL, mixed $protocol = NULL, boolean $index = bool FALSE)

Creates a style sheet link element.

echo HTML::style('media/css/screen.css');
http_header_value  ? 
close

Kohana_HTTP_Header_Value represents a value assigned to an HTTP header, i.e.

 Accept: [key=]value[; property[=property_value][; ...]]

Values are either single values,

properties
default_quality
close

HTTP_Header_Value::default_quality

The default quality header property value

key
close

HTTP_Header_Value::key

properties
close

HTTP_Header_Value::properties

value
close

HTTP_Header_Value::value

methods
key
close

HTTP_Header_Value::key(string $key = NULL)

Provides direct access to the key of this header value

parse_key_value
close

HTTP_Header_Value::parse_key_value(string $string, string $separator = string(1) "=")

Detects and returns key/value pairs

properties
close

HTTP_Header_Value::properties(array $properties = array(0) )

Provides direct access to the properties of this header value

value
close

HTTP_Header_Value::value(string $value = NULL)

Provides direct access to the value of this header value

http_header  ? 
close

The Kohana_HTTP_Header class provides an Object-Orientated interface to HTTP headers. This can parse header arrays returned from the PHP functions apache_request_headers() or the http_parse_headers() function available within the PECL HTTP library.

properties
default_sort_filter
close

HTTP_Header::default_sort_filter

Default positive filter for sorting header values

sort_by_quality
close

HTTP_Header::sort_by_quality

Controls whether to automatically sort headers by quality value

methods
append
close

HTTP_Header::append()

append
close

HTTP_Header::append()

asort
close

HTTP_Header::asort()

asort
close

HTTP_Header::asort()

count
close

HTTP_Header::count()

count
close

HTTP_Header::count()

exchangeArray
close

HTTP_Header::exchangeArray(array $array)

Overloads the ArrayObject::exchangeArray() method to ensure all values passed are parsed correctly into a Kohana_HTTP_Header_Value.

// Input new headers
$headers->exchangeArray(array(
     'date'          => 'Wed, 24 Nov 2010 21:09:23 GMT',
     'cache-control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
));
exchangeArray
close

HTTP_Header::exchangeArray(array $array)

Overloads the ArrayObject::exchangeArray() method to ensure all values passed are parsed correctly into a Kohana_HTTP_Header_Value.

// Input new headers
$headers->exchangeArray(array(
     'date'          => 'Wed, 24 Nov 2010 21:09:23 GMT',
     'cache-control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
));
getArrayCopy
close

HTTP_Header::getArrayCopy()

getArrayCopy
close

HTTP_Header::getArrayCopy()

getFlags
close

HTTP_Header::getFlags()

getFlags
close

HTTP_Header::getFlags()

getIterator
close

HTTP_Header::getIterator()

getIterator
close

HTTP_Header::getIterator()

getIteratorClass
close

HTTP_Header::getIteratorClass()

getIteratorClass
close

HTTP_Header::getIteratorClass()

ksort
close

HTTP_Header::ksort()

ksort
close

HTTP_Header::ksort()

natcasesort
close

HTTP_Header::natcasesort()

natcasesort
close

HTTP_Header::natcasesort()

natsort
close

HTTP_Header::natsort()

natsort
close

HTTP_Header::natsort()

offsetExists
close

HTTP_Header::offsetExists()

offsetExists
close

HTTP_Header::offsetExists()

offsetGet
close

HTTP_Header::offsetGet()

offsetGet
close

HTTP_Header::offsetGet()

offsetSet
close

HTTP_Header::offsetSet(mixed $index, mixed $newval)

Overloads the ArrayObject::offsetSet method to ensure any access is correctly converted to the correct object type.

// Add a new header from encoded string
$headers['cache-control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
offsetSet
close

HTTP_Header::offsetSet(mixed $index, mixed $newval)

Overloads the ArrayObject::offsetSet method to ensure any access is correctly converted to the correct object type.

// Add a new header from encoded string
$headers['cache-control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
offsetUnset
close

HTTP_Header::offsetUnset()

offsetUnset
close

HTTP_Header::offsetUnset()

parse_header_values
close

HTTP_Header::parse_header_values(array $header_values, array $header_commas_allowed = array(3) ( 0 => string(10) "user-agent" 1 => string(4) "date" 2 => string(7) "expires" ))

Parses HTTP Header values and creating an appropriate object depending on type; i.e. accept-type, accept-char, cache-control etc.

$header_values_array = HTTP_Header::parse_header_values(array('cache-control' => 'max-age=200; public'));
setFlags
close

HTTP_Header::setFlags()

setFlags
close

HTTP_Header::setFlags()

setIteratorClass
close

HTTP_Header::setIteratorClass()

setIteratorClass
close

HTTP_Header::setIteratorClass()

sort_values_by_quality
close

HTTP_Header::sort_values_by_quality(array $filter = array(0) )

Sort the headers by quality property if the header matches the Kohana_HTTP_Header::$default_sort_filter definition.

Default sort values

  • Accept
  • Accept-Chars
  • Accept-Encoding
  • Accept-Lang
uasort
close

HTTP_Header::uasort()

uasort
close

HTTP_Header::uasort()

uksort
close

HTTP_Header::uksort()

uksort
close

HTTP_Header::uksort()

# _sort_by_comparison
close

HTTP_Header::_sort_by_comparison()

http_interaction  ? 
close
methods
body
close

HTTP_Interaction::body(string $content = NULL)

Gets or sets the HTTP body to the request or response. The body is included after the header, separated by a single empty new line.

headers
close

HTTP_Interaction::headers(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP headers to the request or response. All headers are included immediately after the HTTP protocol definition during transmission. This method provides a simple array or key/value interface to the headers.

protocol
close

HTTP_Interaction::protocol(string $protocol = NULL)

Gets or sets the HTTP protocol. The standard protocol to use is HTTP/1.1.

render
close

HTTP_Interaction::render()

Renders the HTTP_Interaction to a string, producing

  • Protocol
  • Headers
  • Body
http_request  ? 
close
methods
body
close

HTTP_Request::body(string $content = NULL)

Gets or sets the HTTP body to the request or response. The body is included after the header, separated by a single empty new line.

headers
close

HTTP_Request::headers(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP headers to the request or response. All headers are included immediately after the HTTP protocol definition during transmission. This method provides a simple array or key/value interface to the headers.

method
close

HTTP_Request::method(string $method = NULL)

Gets or sets the HTTP method. Usually GET, POST, PUT or DELETE in traditional CRUD applications.

post
close

HTTP_Request::post(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP POST parameters to the request.

protocol
close

HTTP_Request::protocol(string $protocol = NULL)

Gets or sets the HTTP protocol. The standard protocol to use is HTTP/1.1.

query
close

HTTP_Request::query(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP query string.

render
close

HTTP_Request::render()

Renders the HTTP_Interaction to a string, producing

  • Protocol
  • Headers
  • Body
uri
close

HTTP_Request::uri(array $params = array(0) )

Gets the URI of this request, optionally allows setting of Route specific parameters during the URI generation. If no parameters are passed, the request will use the default values defined in the Route.

http_response  ? 
close
methods
body
close

HTTP_Response::body(string $content = NULL)

Gets or sets the HTTP body to the request or response. The body is included after the header, separated by a single empty new line.

headers
close

HTTP_Response::headers(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP headers to the request or response. All headers are included immediately after the HTTP protocol definition during transmission. This method provides a simple array or key/value interface to the headers.

protocol
close

HTTP_Response::protocol(string $protocol = NULL)

Gets or sets the HTTP protocol. The standard protocol to use is HTTP/1.1.

render
close

HTTP_Response::render()

Renders the HTTP_Interaction to a string, producing

  • Protocol
  • Headers
  • Body
status
close

HTTP_Response::status(integer $code = NULL)

Sets or gets the HTTP status from this response.

 // Set the HTTP status to 404 Not Found
 $response = Response::factory()
         ->status(404);

 // Get the current status
 $status = $response->status();
http  ? 
close
abstract

Contains the most low-level helpers methods in Kohana:

  • Environment initialization
  • Locating files within the cascading filesystem
  • Auto-loading and transparent extension of classes
  • Variable and path debugging
properties
protocol
close

HTTP::protocol

default protocol to use if it cannot be detected

version
close

HTTP::version

default protocol version to use if cannot be detected

methods
parse_header_string
close

HTTP::parse_header_string(string $header_string)

Parses a HTTP header string into an associative array

request_headers
close

HTTP::request_headers()

Parses the the HTTP request headers and returns an array containing key value pairs. This method is slow, but provides an accurate representation of the HTTP request.

 // Get http headers into the request
 $request->headers = HTTP::request_headers();
www_form_urlencode
close

HTTP::www_form_urlencode(array $params = array(0) )

Processes an array of key value pairs and encodes the values to meet RFC 3986

i18n  ? 
close

Internationalization (i18n) class. Provides language loading and translation methods without dependencies on gettext.

Typically this class would never be used directly, but used via the __() function, which loads the message and replaces parameters:

// Display a translated message
echo __('Hello, world');

// With parameter replacement
echo __('Hello, :user', array(':user' => $username));
properties
lang
close

I18n::lang

target language: en-us, es-es, zh-cn, etc

source
close

I18n::source

source language: en-us, es-es, zh-cn, etc

# _cache
close

I18n::_cache

cache of loaded languages

methods
get
close

I18n::get(string $string, string $lang = NULL)

Returns translation of a string. If no translation exists, the original string will be returned. No parameters are replaced.

$hello = I18n::get('Hello friends, my name is :name');
lang
close

I18n::lang(string $lang = NULL)

Get and set the target language.

// Get the current language
$lang = I18n::lang();

// Change the current language to Spanish
I18n::lang('es-es');
load
close

I18n::load(string $lang)

Returns the translation table for a given language.

// Get all defined Spanish messages
$messages = I18n::load('es-es');
inflector  ? 
close

Inflector helper class. Inflection is changing the form of a word based on the context it is used in. For example, changing a word into a plural form.

Inflection is only tested with English, and is will not work with other languages.

properties
# cache
close

Inflector::cache

cached inflections

# irregular
close

Inflector::irregular

irregular words

# uncountable
close

Inflector::uncountable

uncountable words

methods
camelize
close

Inflector::camelize(string $str)

Makes a phrase camel case. Spaces and underscores will be removed.

$str = Inflector::camelize('mother cat');     // "motherCat"
$str = Inflector::camelize('kittens in bed'); // "kittensInBed"
decamelize
close

Inflector::decamelize(string $str, string $sep = string(1) " ")

Converts a camel case phrase into a spaced phrase.

$str = Inflector::decamelize('houseCat');    // "house cat"
$str = Inflector::decamelize('kingAllyCat'); // "king ally cat"
humanize
close

Inflector::humanize(string $str)

Makes an underscored or dashed phrase human-readable.

$str = Inflector::humanize('kittens-are-cats'); // "kittens are cats"
$str = Inflector::humanize('dogs_as_well');     // "dogs as well"
plural
close

Inflector::plural(string $str, integer $count = NULL)

Makes a singular word plural.

echo Inflector::plural('fish'); // "fish", uncountable
echo Inflector::plural('cat');  // "cats"

You can also provide the count to make inflection more intelligent. In this case, it will only return the plural value if the count is not one.

echo Inflector::singular('cats', 3); // "cats"

Special inflections are defined in config/inflector.php.

singular
close

Inflector::singular(string $str, integer $count = NULL)

Makes a plural word singular.

echo Inflector::singular('cats'); // "cat"
echo Inflector::singular('fish'); // "fish", uncountable

You can also provide the count to make inflection more intelligent. In this case, it will only return the singular value if the count is greater than one and not zero.

echo Inflector::singular('cats', 2); // "cats"

Special inflections are defined in config/inflector.php.

uncountable
close

Inflector::uncountable(string $str)

Checks if a word is defined as uncountable. An uncountable word has a single form. For instance, one "fish" and many "fish", not "fishes".

Inflector::uncountable('fish'); // TRUE
Inflector::uncountable('cat');  // FALSE

If you find a word is being pluralized improperly, it has probably not been defined as uncountable in config/inflector.php. If this is the case, please report an issue.

underscore
close

Inflector::underscore(string $str)

Makes a phrase underscored instead of spaced.

$str = Inflector::underscore('five cats'); // "five_cats";
kohana_core  ? 
close

Contains the most low-level helpers methods in Kohana:

  • Environment initialization
  • Locating files within the cascading filesystem
  • Auto-loading and transparent extension of classes
  • Variable and path debugging
properties
base_url
close

Kohana_Core::base_url

base URL to the application

cache_dir
close

Kohana_Core::cache_dir

Cache directory, used by Kohana::cache. Set by Kohana::init

cache_life
close

Kohana_Core::cache_life

Default lifetime for caching, in seconds, used by Kohana::cache. Set by Kohana::init

caching
close

Kohana_Core::caching

Whether to use internal caching for Kohana::find_file, does not apply to Kohana::cache. Set by Kohana::init

charset
close

Kohana_Core::charset

character set of input and output

config
close

Kohana_Core::config

config object

content_type
close

Kohana_Core::content_type

environment
close

Kohana_Core::environment

Current environment name

errors
close

Kohana_Core::errors

Enable Kohana catching and displaying PHP errors and exceptions. Set by Kohana::init

expose
close

Kohana_Core::expose

set the X-Powered-By header

hostnames
close

Kohana_Core::hostnames

list of valid host names for this instance

index_file
close

Kohana_Core::index_file

Application index file, added to links generated by Kohana. Set by Kohana::init

is_cli
close

Kohana_Core::is_cli

True if Kohana is running from the command line

is_windows
close

Kohana_Core::is_windows

True if Kohana is running on windows

log
close

Kohana_Core::log

logging object

log_errors
close

Kohana_Core::log_errors

Should errors and exceptions be logged

magic_quotes
close

Kohana_Core::magic_quotes

True if magic quotes is enabled.

profiling
close

Kohana_Core::profiling

Whether to enable profiling. Set by Kohana::init

safe_mode
close

Kohana_Core::safe_mode

TRUE if PHP safe mode is on

server_name
close

Kohana_Core::server_name

the name of the server Kohana is hosted upon

shutdown_errors
close

Kohana_Core::shutdown_errors

Types of errors to display at shutdown

# _files
close

Kohana_Core::_files

File path cache, used when caching is true in Kohana::init

# _files_changed
close

Kohana_Core::_files_changed

Has the file path cache changed during this execution? Used internally when when caching is true in Kohana::init

# _init
close

Kohana_Core::_init

Has Kohana::init been called?

# _modules
close

Kohana_Core::_modules

Currently active modules

# _paths
close

Kohana_Core::_paths

Include paths that are used to find files

methods
auto_load
close

Kohana_Core::auto_load(string $class)

Provides auto-loading support of classes that follow Kohana's class naming conventions. See Loading Classes for more information.

Class names are converted to file names by making the class name lowercase and converting underscores to slashes:

// Loads classes/my/class/name.php
Kohana::auto_load('My_Class_Name');

You should never have to call this function, as simply calling a class will cause it to be called.

This function must be enabled as an autoloader in the bootstrap:

spl_autoload_register(array('Kohana', 'auto_load'));
cache
close

Kohana_Core::cache(string $name, mixed $data = NULL, integer $lifetime = NULL)

Provides simple file-based caching for strings and arrays:

// Set the "foo" cache
Kohana::cache('foo', 'hello, world');

// Get the "foo" cache
$foo = Kohana::cache('foo');

All caches are stored as PHP code, generated with var_export. Caching objects may not work as expected. Storing references or an object or array that has recursion will cause an E_FATAL.

The cache directory and default cache lifetime is set by Kohana::init

config
close

Kohana_Core::config(string $group)

Returns the configuration array for the requested group. See configuration files for more information.

// Get all the configuration in config/database.php
$config = Kohana::config('database');

// Get only the default connection configuration
$default = Kohana::config('database.default')

// Get only the hostname of the default connection
$host = Kohana::config('database.default.connection.hostname')
deinit
close

Kohana_Core::deinit()

Cleans up the environment:

  • Restore the previous error and exception handlers
  • Destroy the Kohana::$log and Kohana::$config objects
error_handler
close

Kohana_Core::error_handler()

PHP error handler, converts all errors into ErrorExceptions. This handler respects error_reporting settings.

find_file
close

Kohana_Core::find_file(string $dir, string $file, string $ext = NULL, boolean $array = bool FALSE)

Searches for a file in the Cascading Filesystem, and returns the path to the file that has the highest precedence, so that it can be included.

When searching the "config", "messages", or "i18n" directories, or when the $array flag is set to true, an array of all the files that match that path in the Cascading Filesystem will be returned. These files will return arrays which must be merged together.

If no extension is given, the default extension (EXT set in index.php) will be used.

// Returns an absolute path to views/template.php
Kohana::find_file('views', 'template');

// Returns an absolute path to media/css/style.css
Kohana::find_file('media', 'css/style', 'css');

// Returns an array of all the "mimes" configuration files
Kohana::find_file('config', 'mimes');
globals
close

Kohana_Core::globals()

Reverts the effects of the register_globals PHP setting by unsetting all global varibles except for the default super globals (GPCS, etc), which is a potential security hole.

This is called automatically by Kohana::init if register_globals is on.

include_paths
close

Kohana_Core::include_paths()

Returns the the currently active include paths, including the application, system, and each module's path.

init
close

Kohana_Core::init(array $settings = NULL)

Initializes the environment:

  • Disables register_globals and magic_quotes_gpc
  • Determines the current environment
  • Set global settings
  • Sanitizes GET, POST, and COOKIE variables
  • Converts GET, POST, and COOKIE variables to the global character set

The following settings can be set:

Type Setting Description Default Value
string base_url The base URL for your application. This should be the relative path from your DOCROOT to your index.php file, in other words, if Kohana is in a subfolder, set this to the subfolder name, otherwise leave it as the default. The leading slash is required, trailing slash is optional. "/"
string index_file The name of the front controller. This is used by Kohana to generate relative urls like HTML::anchor() and URL::base(). This is usually index.php. To remove index.php from your urls, set this to FALSE. "index.php"
string charset Character set used for all input and output "utf-8"
string cache_dir Kohana's cache directory. Used by Kohana::cache for simple internal caching, like Fragments and [caching database queries](this should link somewhere). This has nothing to do with the Cache module. APPPATH."cache"
integer cache_life Lifetime, in seconds, of items cached by Kohana::cache 60
boolean errors Should Kohana catch PHP errors and uncaught Exceptions and show the error_view. See Error Handling for more info.

Recommended setting: TRUE while developing, FALSE on production servers.
TRUE
boolean profile Whether to enable the Profiler.

Recommended setting: TRUE while developing, FALSE on production servers.
TRUE * boolean | caching | Cache file locations to speed up Kohana::find_file. This has nothing to do with Kohana::cache, Fragments or the Cache module.

Recommended setting: FALSE while developing, TRUE on production servers. | FALSE
list_files
close

Kohana_Core::list_files(string $directory = NULL, array $paths = NULL)

Recursively finds all of the files in the specified directory at any location in the Cascading Filesystem, and returns an array of all the files found, sorted alphabetically.

// Find all view files.
$views = Kohana::list_files('views');
load
close

Kohana_Core::load(string $file)

Loads a file within a totally empty scope and returns the output:

$foo = Kohana::load('foo.php');
message
close

Kohana_Core::message(string $file, string $path = NULL, mixed $default = NULL)

Get a message from a file. Messages are arbitary strings that are stored in the messages/ directory and reference by a key. Translation is not performed on the returned values. See message files for more information.

// Get "username" from messages/text.php
$username = Kohana::message('text', 'username');
modules
close

Kohana_Core::modules(array $modules = NULL)

Changes the currently enabled modules. Module paths may be relative or absolute, but must point to a directory:

Kohana::modules(array('modules/foo', MODPATH.'bar'));
sanitize
close

Kohana_Core::sanitize(mixed $value)

Recursively sanitizes an input variable:

  • Strips slashes if magic quotes are enabled
  • Normalizes all newlines to LF
shutdown_handler
close

Kohana_Core::shutdown_handler()

Catches errors that are not caught by the error handler, such as E_PARSE.

kohana  ? 
close

Contains the most low-level helpers methods in Kohana:

  • Environment initialization
  • Locating files within the cascading filesystem
  • Auto-loading and transparent extension of classes
  • Variable and path debugging
properties
base_url
close

Kohana::base_url

base URL to the application

cache_dir
close

Kohana::cache_dir

Cache directory, used by Kohana::cache. Set by Kohana::init

cache_life
close

Kohana::cache_life

Default lifetime for caching, in seconds, used by Kohana::cache. Set by Kohana::init

caching
close

Kohana::caching

Whether to use internal caching for Kohana::find_file, does not apply to Kohana::cache. Set by Kohana::init

charset
close

Kohana::charset

character set of input and output

config
close

Kohana::config

config object

content_type
close

Kohana::content_type

environment
close

Kohana::environment

Current environment name

errors
close

Kohana::errors

Enable Kohana catching and displaying PHP errors and exceptions. Set by Kohana::init

expose
close

Kohana::expose

set the X-Powered-By header

hostnames
close

Kohana::hostnames

list of valid host names for this instance

index_file
close

Kohana::index_file

Application index file, added to links generated by Kohana. Set by Kohana::init

is_cli
close

Kohana::is_cli

True if Kohana is running from the command line

is_windows
close

Kohana::is_windows

True if Kohana is running on windows

log
close

Kohana::log

logging object

log_errors
close

Kohana::log_errors

Should errors and exceptions be logged

magic_quotes
close

Kohana::magic_quotes

True if magic quotes is enabled.

profiling
close

Kohana::profiling

Whether to enable profiling. Set by Kohana::init

safe_mode
close

Kohana::safe_mode

TRUE if PHP safe mode is on

server_name
close

Kohana::server_name

the name of the server Kohana is hosted upon

shutdown_errors
close

Kohana::shutdown_errors

Types of errors to display at shutdown

# _files
close

Kohana::_files

File path cache, used when caching is true in Kohana::init

# _files_changed
close

Kohana::_files_changed

Has the file path cache changed during this execution? Used internally when when caching is true in Kohana::init

# _init
close

Kohana::_init

Has Kohana::init been called?

# _modules
close

Kohana::_modules

Currently active modules

# _paths
close

Kohana::_paths

Include paths that are used to find files

methods
auto_load
close

Kohana::auto_load(string $class)

Provides auto-loading support of classes that follow Kohana's class naming conventions. See Loading Classes for more information.

Class names are converted to file names by making the class name lowercase and converting underscores to slashes:

// Loads classes/my/class/name.php
Kohana::auto_load('My_Class_Name');

You should never have to call this function, as simply calling a class will cause it to be called.

This function must be enabled as an autoloader in the bootstrap:

spl_autoload_register(array('Kohana', 'auto_load'));
cache
close

Kohana::cache(string $name, mixed $data = NULL, integer $lifetime = NULL)

Provides simple file-based caching for strings and arrays:

// Set the "foo" cache
Kohana::cache('foo', 'hello, world');

// Get the "foo" cache
$foo = Kohana::cache('foo');

All caches are stored as PHP code, generated with var_export. Caching objects may not work as expected. Storing references or an object or array that has recursion will cause an E_FATAL.

The cache directory and default cache lifetime is set by Kohana::init

config
close

Kohana::config(string $group)

Returns the configuration array for the requested group. See configuration files for more information.

// Get all the configuration in config/database.php
$config = Kohana::config('database');

// Get only the default connection configuration
$default = Kohana::config('database.default')

// Get only the hostname of the default connection
$host = Kohana::config('database.default.connection.hostname')
deinit
close

Kohana::deinit()

Cleans up the environment:

  • Restore the previous error and exception handlers
  • Destroy the Kohana::$log and Kohana::$config objects
error_handler
close

Kohana::error_handler()

PHP error handler, converts all errors into ErrorExceptions. This handler respects error_reporting settings.

find_file
close

Kohana::find_file(string $dir, string $file, string $ext = NULL, boolean $array = bool FALSE)

Searches for a file in the Cascading Filesystem, and returns the path to the file that has the highest precedence, so that it can be included.

When searching the "config", "messages", or "i18n" directories, or when the $array flag is set to true, an array of all the files that match that path in the Cascading Filesystem will be returned. These files will return arrays which must be merged together.

If no extension is given, the default extension (EXT set in index.php) will be used.

// Returns an absolute path to views/template.php
Kohana::find_file('views', 'template');

// Returns an absolute path to media/css/style.css
Kohana::find_file('media', 'css/style', 'css');

// Returns an array of all the "mimes" configuration files
Kohana::find_file('config', 'mimes');
globals
close

Kohana::globals()

Reverts the effects of the register_globals PHP setting by unsetting all global varibles except for the default super globals (GPCS, etc), which is a potential security hole.

This is called automatically by Kohana::init if register_globals is on.

include_paths
close

Kohana::include_paths()

Returns the the currently active include paths, including the application, system, and each module's path.

init
close

Kohana::init(array $settings = NULL)

Initializes the environment:

  • Disables register_globals and magic_quotes_gpc
  • Determines the current environment
  • Set global settings
  • Sanitizes GET, POST, and COOKIE variables
  • Converts GET, POST, and COOKIE variables to the global character set

The following settings can be set:

Type Setting Description Default Value
string base_url The base URL for your application. This should be the relative path from your DOCROOT to your index.php file, in other words, if Kohana is in a subfolder, set this to the subfolder name, otherwise leave it as the default. The leading slash is required, trailing slash is optional. "/"
string index_file The name of the front controller. This is used by Kohana to generate relative urls like HTML::anchor() and URL::base(). This is usually index.php. To remove index.php from your urls, set this to FALSE. "index.php"
string charset Character set used for all input and output "utf-8"
string cache_dir Kohana's cache directory. Used by Kohana::cache for simple internal caching, like Fragments and [caching database queries](this should link somewhere). This has nothing to do with the Cache module. APPPATH."cache"
integer cache_life Lifetime, in seconds, of items cached by Kohana::cache 60
boolean errors Should Kohana catch PHP errors and uncaught Exceptions and show the error_view. See Error Handling for more info.

Recommended setting: TRUE while developing, FALSE on production servers.
TRUE
boolean profile Whether to enable the Profiler.

Recommended setting: TRUE while developing, FALSE on production servers.
TRUE * boolean | caching | Cache file locations to speed up Kohana::find_file. This has nothing to do with Kohana::cache, Fragments or the Cache module.

Recommended setting: FALSE while developing, TRUE on production servers. | FALSE
list_files
close

Kohana::list_files(string $directory = NULL, array $paths = NULL)

Recursively finds all of the files in the specified directory at any location in the Cascading Filesystem, and returns an array of all the files found, sorted alphabetically.

// Find all view files.
$views = Kohana::list_files('views');
load
close

Kohana::load(string $file)

Loads a file within a totally empty scope and returns the output:

$foo = Kohana::load('foo.php');
message
close

Kohana::message(string $file, string $path = NULL, mixed $default = NULL)

Get a message from a file. Messages are arbitary strings that are stored in the messages/ directory and reference by a key. Translation is not performed on the returned values. See message files for more information.

// Get "username" from messages/text.php
$username = Kohana::message('text', 'username');
modules
close

Kohana::modules(array $modules = NULL)

Changes the currently enabled modules. Module paths may be relative or absolute, but must point to a directory:

Kohana::modules(array('modules/foo', MODPATH.'bar'));
sanitize
close

Kohana::sanitize(mixed $value)

Recursively sanitizes an input variable:

  • Strips slashes if magic quotes are enabled
  • Normalizes all newlines to LF
shutdown_handler
close

Kohana::shutdown_handler()

Catches errors that are not caught by the error handler, such as E_PARSE.

log_file  ? 
close

File log writer. Writes out messages and stores them in a YYYY/MM directory.

properties
# _directory
close

Log_File::_directory

Directory to place log files in

# _log_levels
close

Log_File::_log_levels

methods
write
close

Log_File::write(array $messages)

Writes each of the messages into the log file. The log file will be appended to the YYYY/MM/DD.log.php file, where YYYY is the current year, MM is the current month, and DD is the current day.

$writer->write($messages);
log_stderr  ? 
close

STDERR log writer. Writes out messages to STDERR.

properties
# _log_levels
close

Log_StdErr::_log_levels

methods
write
close

Log_StdErr::write(array $messages)

Writes each of the messages to STDERR.

$writer->write($messages);
log_stdout  ? 
close

STDOUT log writer. Writes out messages to STDOUT.

properties
# _log_levels
close

Log_StdOut::_log_levels

methods
write
close

Log_StdOut::write(array $messages)

Writes each of the messages to STDOUT.

$writer->write($messages);
log_syslog  ? 
close

Syslog log writer.

properties
# _ident
close

Log_Syslog::_ident

The syslog identifier

# _log_levels
close

Log_Syslog::_log_levels

# _syslog_levels
close

Log_Syslog::_syslog_levels

log levels

methods
write
close

Log_Syslog::write(array $messages)

Writes each of the messages into the syslog.

log_writer  ? 
close
abstract

Log writer abstract class. All Log writers must extend this class.

properties
# _log_levels
close

Log_Writer::_log_levels

methods
write
close

Log_Writer::write(array $messages)

Write an array of messages.

$writer->write($messages);
log  ? 
close

Message logging with observer-based log writing.

This class does not support extensions, only additional writers.

properties
timestamp
close

Log::timestamp

timestamp format for log entries

timezone
close

Log::timezone

timezone for log entries

write_on_add
close

Log::write_on_add

immediately write when logs are added

# _instance
close

Log::_instance

Singleton instance container

# _messages
close

Log::_messages

list of added messages

# _writers
close

Log::_writers

list of log writers

methods
add
close

Log::add(string $level, string $message, array $values = NULL)

Adds a message to the log. Replacement values must be passed in to be replaced using strtr.

$log->add(Log::ERROR, 'Could not locate user: :user', array(
    ':user' => $username,
));
attach
close

Log::attach(object $writer, mixed $levels = array(0) , integer $min_level = integer 0)

Attaches a log writer, and optionally limits the levels of messages that will be written by the writer.

$log->attach($writer);
detach
close

Log::detach(object $writer)

Detaches a log writer. The same writer object must be used.

$log->detach($writer);
instance
close

Log::instance()

Get the singleton instance of this class and enable writing at shutdown.

$log = Log::instance();
write
close

Log::write()

Write and clear all of the messages.

$log->write();
model  ? 
close
abstract

Model base class. All models should extend this class.

methods
factory
close

Model::factory(string $name)

Create a new model instance.

$model = Model::factory($name);
num  ? 
close

Number helper class. Provides additional formatting methods that for working with numbers.

properties
byte_units
close

Num::byte_units

Valid byte units => power of 2 that defines the unit's size

methods
bytes
close

Num::bytes(string $size)

Converts a file size number to a byte value. File sizes are defined in the format: SB, where S is the size (1, 8.5, 300, etc.) and B is the byte unit (K, MiB, GB, etc.). All valid byte units are defined in Num::$byte_units

echo Num::bytes('200K');  // 204800
echo Num::bytes('5MiB');  // 5242880
echo Num::bytes('1000');  // 1000
echo Num::bytes('2.5GB'); // 2684354560
format
close

Num::format(float $number, integer $places, boolean $monetary = bool FALSE)

Locale-aware number and monetary formatting.

// In English, "1,200.05"
// In Spanish, "1200,05"
// In Portuguese, "1 200,05"
echo Num::format(1200.05, 2);

// In English, "1,200.05"
// In Spanish, "1.200,05"
// In Portuguese, "1.200.05"
echo Num::format(1200.05, 2, TRUE);
ordinal
close

Num::ordinal(integer $number)

Returns the English ordinal suffix (th, st, nd, etc) of a number.

echo 2, Num::ordinal(2);   // "2nd"
echo 10, Num::ordinal(10); // "10th"
echo 33, Num::ordinal(33); // "33rd"
round
close

Num::round(float $value, integer $precision = integer 0, integer $mode = integer 1, boolean $native = bool TRUE)

Round a number to a specified precision, using a specified tie breaking technique

profiler  ? 
close

Provides simple benchmarking and profiling. To display the statistics that have been collected, load the profiler/stats View:

echo View::factory('profiler/stats');
properties
rollover
close

Profiler::rollover

maximium number of application stats to keep

# _marks
close

Profiler::_marks

collected benchmarks

methods
application
close

Profiler::application()

Gets the total application run time and memory usage. Caches the result so that it can be compared between requests.

list($time, $memory) = Profiler::application();
delete
close

Profiler::delete(string $token)

Deletes a benchmark. If an error occurs during the benchmark, it is recommended to delete the benchmark to prevent statistics from being adversely affected.

Profiler::delete($token);
group_stats
close

Profiler::group_stats(mixed $groups = NULL)

Gets the min, max, average and total of profiler groups as an array.

$stats = Profiler::group_stats('test');
groups
close

Profiler::groups()

Returns all the benchmark tokens by group and name as an array.

$groups = Profiler::groups();
start
close

Profiler::start(string $group, string $name)

Starts a new benchmark and returns a unique token. The returned token must be used when stopping the benchmark.

$token = Profiler::start('test', 'profiler');
stats
close

Profiler::stats(array $tokens)

Gets the min, max, average and total of a set of tokens as an array.

$stats = Profiler::stats($tokens);
stop
close

Profiler::stop(string $token)

Stops a benchmark.

Profiler::stop($token);
total
close

Profiler::total(string $token)

Gets the total execution time and memory usage of a benchmark as a list.

list($time, $memory) = Profiler::total($token);
request_client_external
properties
# _allow_private_cache
close

Request_Client_External::_allow_private_cache

Defines whether this client should cache private cache directives

# _cache
close

Request_Client_External::_cache

Caching library for request caching

# _options
close

Request_Client_External::_options

additional curl options to use on execution

# _processed_headers
close

Request_Client_External::_processed_headers

internal header cache for curl processing

# _request_time
close

Request_Client_External::_request_time

The timestamp of the request

# _response_time
close

Request_Client_External::_response_time

The timestamp of the response

methods
allow_private_cache
close

Request_Client_External::allow_private_cache(boolean $setting = NULL)

Gets or sets the Request_Client::allow_private_cache setting. If set to TRUE, the client will also cache cache-control directives that have the private setting.

cache
close

Request_Client_External::cache(Kohana_Cache $cache = NULL)

Getter and setter for the internal caching engine, used to cache responses if available and valid.

cache_lifetime
close

Request_Client_External::cache_lifetime(Response $response)

Calculates the total Time To Live based on the specification RFC 2616 cache lifetime rules.

cache_response
close

Request_Client_External::cache_response(Request $request, Response $response = NULL)

Caches a Response using the supplied Cache and the key generated by Request_Client::_create_cache_key.

If not response is supplied, the cache will be checked for an existing one that is available.

create_cache_key
close

Request_Client_External::create_cache_key(Request $request)

Creates a cache key for the request to use for caching Kohana_Response returned by Request::execute.

execute
close

Request_Client_External::execute(Request $request)

Processes the request, executing the controller action that handles this request, determined by the Route.

  1. Before the controller action is called, the Controller::before method will be called.
  2. Next the controller action will be called.
  3. After the controller action is called, the Controller::after method will be called.

By default, the output from the controller is captured and returned, and no headers are sent.

$request->execute();
invalidate_cache
close

Request_Client_External::invalidate_cache(Request $request)

Invalidate a cached response for the Request supplied. This has the effect of deleting the response from the Cache entry.

options
close

Request_Client_External::options(mixed $key = NULL, mixed $value = NULL)

Set and get options for this request.

request_execution_time
close

Request_Client_External::request_execution_time()

Returns the duration of the last request execution. Either returns the time of completed requests or FALSE if the request hasn't finished executing, or is yet to be run.

set_cache
close

Request_Client_External::set_cache(Response $response)

Controls whether the response can be cached. Uses HTTP protocol to determine whether the response can be cached.

# _curl_execute
close

Request_Client_External::_curl_execute(Request $request)

Execute the request using the CURL extension. (recommended)

# _http_execute
close

Request_Client_External::_http_execute(Request $request)

Execute the request using the PECL HTTP extension. (recommended)

# _native_execute
close

Request_Client_External::_native_execute(Request $request)

Execute the request using PHP stream. (not recommended)

# _parse_headers
close

Request_Client_External::_parse_headers(resource $remote, string $header)

Parses the returned headers from the remote request

request_client_internal  ? 
close

Request Client for internal execution

properties
# _allow_private_cache
close

Request_Client_Internal::_allow_private_cache

Defines whether this client should cache private cache directives

# _cache
close

Request_Client_Internal::_cache

Caching library for request caching

# _previous_environment
close

Request_Client_Internal::_previous_environment

# _request_time
close

Request_Client_Internal::_request_time

The timestamp of the request

# _response_time
close

Request_Client_Internal::_response_time

The timestamp of the response

methods
allow_private_cache
close

Request_Client_Internal::allow_private_cache(boolean $setting = NULL)

Gets or sets the Request_Client::allow_private_cache setting. If set to TRUE, the client will also cache cache-control directives that have the private setting.

cache
close

Request_Client_Internal::cache(Kohana_Cache $cache = NULL)

Getter and setter for the internal caching engine, used to cache responses if available and valid.

cache_lifetime
close

Request_Client_Internal::cache_lifetime(Response $response)

Calculates the total Time To Live based on the specification RFC 2616 cache lifetime rules.

cache_response
close

Request_Client_Internal::cache_response(Request $request, Response $response = NULL)

Caches a Response using the supplied Cache and the key generated by Request_Client::_create_cache_key.

If not response is supplied, the cache will be checked for an existing one that is available.

create_cache_key
close

Request_Client_Internal::create_cache_key(Request $request)

Creates a cache key for the request to use for caching Kohana_Response returned by Request::execute.

execute
close

Request_Client_Internal::execute(Request $request)

Processes the request, executing the controller action that handles this request, determined by the Route.

  1. Before the controller action is called, the Controller::before method will be called.
  2. Next the controller action will be called.
  3. After the controller action is called, the Controller::after method will be called.

By default, the output from the controller is captured and returned, and no headers are sent.

$request->execute();

        will be removed in 3.2
invalidate_cache
close

Request_Client_Internal::invalidate_cache(Request $request)

Invalidate a cached response for the Request supplied. This has the effect of deleting the response from the Cache entry.

request_execution_time
close

Request_Client_Internal::request_execution_time()

Returns the duration of the last request execution. Either returns the time of completed requests or FALSE if the request hasn't finished executing, or is yet to be run.

set_cache
close

Request_Client_Internal::set_cache(Response $response)

Controls whether the response can be cached. Uses HTTP protocol to determine whether the response can be cached.

request_client  ? 
close
abstract

Request Client

properties
# _allow_private_cache
close

Request_Client::_allow_private_cache

Defines whether this client should cache private cache directives

# _cache
close

Request_Client::_cache

Caching library for request caching

# _request_time
close

Request_Client::_request_time

The timestamp of the request

# _response_time
close

Request_Client::_response_time

The timestamp of the response

methods
allow_private_cache
close

Request_Client::allow_private_cache(boolean $setting = NULL)

Gets or sets the Request_Client::allow_private_cache setting. If set to TRUE, the client will also cache cache-control directives that have the private setting.

cache
close

Request_Client::cache(Kohana_Cache $cache = NULL)

Getter and setter for the internal caching engine, used to cache responses if available and valid.

cache_lifetime
close

Request_Client::cache_lifetime(Response $response)

Calculates the total Time To Live based on the specification RFC 2616 cache lifetime rules.

cache_response
close

Request_Client::cache_response(Request $request, Response $response = NULL)

Caches a Response using the supplied Cache and the key generated by Request_Client::_create_cache_key.

If not response is supplied, the cache will be checked for an existing one that is available.

create_cache_key
close

Request_Client::create_cache_key(Request $request)

Creates a cache key for the request to use for caching Kohana_Response returned by Request::execute.

execute
close

Request_Client::execute(Request $request)

Processes the request, executing the controller action that handles this request, determined by the Route.

  1. Before the controller action is called, the Controller::before method will be called.
  2. Next the controller action will be called.
  3. After the controller action is called, the Controller::after method will be called.

By default, the output from the controller is captured and returned, and no headers are sent.

$request->execute();
invalidate_cache
close

Request_Client::invalidate_cache(Request $request)

Invalidate a cached response for the Request supplied. This has the effect of deleting the response from the Cache entry.

request_execution_time
close

Request_Client::request_execution_time()

Returns the duration of the last request execution. Either returns the time of completed requests or FALSE if the request hasn't finished executing, or is yet to be run.

set_cache
close

Request_Client::set_cache(Response $response)

Controls whether the response can be cached. Uses HTTP protocol to determine whether the response can be cached.

request  ? 
close

Request and response wrapper. Uses the Route class to determine what Controller to send the request to.

properties
client_ip
close

Request::client_ip

client IP address

current
close

Request::current

currently executing request instance

initial
close

Request::initial

main request instance

user_agent
close

Request::user_agent

client user agent

# _action
close

Request::_action

action to be executed in the controller

# _body
close

Request::_body

the body

# _client
close

Request::_client

# _controller
close

Request::_controller

controller to be executed

# _cookies
close

Request::_cookies

cookies to send with the request

# _directory
close

Request::_directory

controller directory

# _external
close

Request::_external

external request

# _get
close

Request::_get

query parameters

# _header
close

Request::_header

headers to sent as part of the request

# _method
close

Request::_method

method: GET, POST, PUT, DELETE, HEAD, etc

# _params
close

Request::_params

parameters from the route

# _post
close

Request::_post

post parameters

# _protocol
close

Request::_protocol

protocol: HTTP/1.1, FTP, CLI, etc

# _referrer
close

Request::_referrer

referring URL

# _requested_with
close

Request::_requested_with

the x-requested-with header which most likely

# _response
close

Request::_response

response

# _route
close

Request::_route

route matched for this request

# _routes
close

Request::_routes

array of routes to manually look at instead of the global namespace

# _uri
close

Request::_uri

the URI of the request

methods
accept_encoding
close

Request::accept_encoding(string $type = NULL)

Returns the accepted encodings. If a specific encoding is defined, the quality of that encoding will be returned. If the encoding is not accepted, FALSE will be returned.

$encodings = Request::accept_encoding();
accept_lang
close

Request::accept_lang(string $lang = NULL)

Returns the accepted languages. If a specific language is defined, the quality of that language will be returned. If the language is not accepted, FALSE will be returned.

$langs = Request::accept_lang();
accept_type
close

Request::accept_type(string $type = NULL)

Returns the accepted content types. If a specific type is defined, the quality of that type will be returned.

$types = Request::accept_type();
action
close

Request::action(string $action = NULL)

Sets and gets the action for the controller.

body
close

Request::body(string $content = NULL)

Gets or sets the HTTP body to the request or response. The body is included after the header, separated by a single empty new line.

controller
close

Request::controller(string $controller = NULL)

Sets and gets the controller for the matched route.

cookie
close

Request::cookie(mixed $key = NULL, string $value = NULL)

Set and get cookies values for this request.

create_response
close

Request::create_response(boolean $bind = bool TRUE)

Creates a response based on the type of request, i.e. an Request_HTTP will produce a Response_HTTP, and the same applies to CLI.

 // Create a response to the request
 $response = $request->create_response();
current
close

Request::current()

Return the currently executing request. This is changed to the current request when Request::execute is called and restored when the request is completed.

$request = Request::current();
detect_uri
close

Request::detect_uri()

Automatically detects the URI of the main request using PATH_INFO, REQUEST_URI, PHP_SELF or REDIRECT_URL.

$uri = Request::detect_uri();
directory
close

Request::directory(string $directory = NULL)

Sets and gets the directory for the controller.

execute
close

Request::execute()

Processes the request, executing the controller action that handles this request, determined by the Route.

  1. Before the controller action is called, the Controller::before method will be called.
  2. Next the controller action will be called.
  3. After the controller action is called, the Controller::after method will be called.

By default, the output from the controller is captured and returned, and no headers are sent.

$request->execute();
factory
close

Request::factory(string $uri = bool TRUE, Cache $cache = NULL, array $injected_routes = array(0) )

Creates a new request object for the given URI. New requests should be created using the Request::instance or Request::factory methods.

$request = Request::factory($uri);

If $cache parameter is set, the response for the request will attempt to be retrieved from the cache.

generate_etag
close

Request::generate_etag()

Generates an ETag from the request response.

$etag = $request->generate_etag();

If the request response is empty when this method is called, an exception will be thrown!

get_client
close

Request::get_client()

Provides readonly access to the Request_Client, useful for accessing the caching methods within the request client.

headers
close

Request::headers(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP headers to the request or response. All headers are included immediately after the HTTP protocol definition during transmission. This method provides a simple array or key/value interface to the headers.

initial
close

Request::initial()

Returns the first request encountered by this framework. This will should only be set once during the first Request::factory invocation.

// Get the first request
$request = Request::initial();

// Test whether the current request is the first request
if (Request::initial() === Request::current())
     // Do something useful
is_ajax
close

Request::is_ajax()

Returns whether this is an ajax request (as used by JS frameworks)

is_initial
close

Request::is_initial()

Returns whether this request is the initial request Kohana received. Can be used to test for sub requests.

if ( ! $request->is_initial())
    // This is a sub request
method
close

Request::method(string $method = NULL)

Gets or sets the HTTP method. Usually GET, POST, PUT or DELETE in traditional CRUD applications.

param
close

Request::param(string $key = NULL, mixed $default = NULL)

Retrieves a value from the route parameters.

$id = $request->param('id');
post
close

Request::post(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP POST parameters to the request.

post_max_size_exceeded
close

Request::post_max_size_exceeded()

Determines if a file larger than the post_max_size has been uploaded. PHP does not handle this situation gracefully on its own, so this method helps to solve that problem.

process_uri
close

Request::process_uri(string $uri, array $routes = NULL)

Process URI

protocol
close

Request::protocol(string $protocol = NULL)

Gets or sets the HTTP protocol. The standard protocol to use is http.

query
close

Request::query(mixed $key = NULL, string $value = NULL)

Gets or sets HTTP query string.

redirect
close

Request::redirect(string $url = string(0) "", integer $code = integer 302)

Redirects as the request response. If the URL does not include a protocol, it will be converted into a complete URL.

$request->redirect($url);

No further processing can be done after this method is called!

referrer
close

Request::referrer(string $referrer = NULL)

Sets and gets the referrer from the request.

render
close

Request::render(boolean $response = bool TRUE)

Renders the HTTP_Interaction to a string, producing

  • Protocol
  • Headers
  • Body

    If there are variables set to the Kohana_Request::$_post they will override any values set to body.

requested_with
close

Request::requested_with(string $requested_with = NULL)

Gets and sets the requested with property, which should be relative to the x-requested-with pseudo header.

response
close

Request::response(Response $response = NULL)

Set or get the response for this request

route
close

Request::route(string $route = NULL)

Sets and gets the route from the request.

send_headers
close

Request::send_headers()

Sends the response status and all set headers. The current server protocol (HTTP/1.0 or HTTP/1.1) will be used when available. If not available, HTTP/1.1 will be used.

$request->send_headers();
uri
close

Request::uri(array $params = NULL)

Generates a relative URI for the current route.

$request->uri($params);
url
close

Request::url(array $params = NULL, mixed $protocol = NULL)

Create a URL from the current request. This is a shortcut for:

echo URL::site($this->request->uri($params), $protocol);
user_agent
close

Request::user_agent(mixed $value)

Returns information about the client user agent.

// Returns "Chrome" when using Google Chrome
$browser = Request::user_agent('browser');

Multiple values can be returned at once by using an array:

// Get the browser and platform with a single call
$info = Request::user_agent(array('browser', 'platform'));

When using an array for the value, an associative array will be returned.

# _parse_accept
close

Request::_parse_accept(string $header, array $accepts = NULL)

Parses an accept header and returns an array (type => quality) of the accepted types, ordered by quality.

$accept = Request::_parse_accept($header, $defaults);
response  ? 
close

Response wrapper. Created as the result of any Request execution or utility method (i.e. Redirect). Implements standard HTTP response format.

properties
messages
close

Response::messages

# _body
close

Response::_body

The response body

# _cookies
close

Response::_cookies

Cookies to be returned in the response

# _header
close

Response::_header

Headers returned in the response

# _protocol
close

Response::_protocol

The response protocol

# _status
close

Response::_status

The response http status

methods
body
close

Response::body()

Gets or sets the body of the response

check_cache
close

Response::check_cache(string $etag = NULL, Request $request = NULL)

Check Cache Checks the browser cache to see the response needs to be returned

content_length
close

Response::content_length()

Returns the length of the body for use with content header

cookie
close

Response::cookie(mixed $key = NULL, string $value = NULL)

Set and get cookies values for this response.

// Get the cookies set to the response
$cookies = $response->cookie();

// Set a cookie to the response
$response->cookie('session', array(
     'value' => $value,
     'expiration' => 12352234
));
create_cache_control
close

Response::create_cache_control(array $cache_control)

Generates a Cache-Control HTTP header based on the supplied array.

// Set the cache control headers you want to use
$cache_control = array(
    'max-age'          => 3600,
    'must-revalidate'  => NULL,
    'public'           => NULL
);

// Create the cache control header, creates :
// cache-control: max-age=3600, must-revalidate, public
$response->header['cache-control'] = Response::create_cache_control($cache_control);
delete_cookie
close

Response::delete_cookie(string $name)

Deletes a cookie set to the response

delete_cookies
close

Response::delete_cookies()

Deletes all cookies from this response

factory
close

Response::factory(array $config = array(0) )

Factory method to create a new Response. Pass properties in using an associative array.

 // Create a new response
 $response = Response::factory();

 // Create a new response with headers
 $response = Response::factory(array('status' => 200));
generate_etag
close

Response::generate_etag()

Generate ETag Generates an ETag from the response ready to be returned

headers
close

Response::headers(mixed $key = NULL, string $value = NULL)

Gets and sets headers to the Response, allowing chaining of response methods. If chaining isn't required, direct access to the property should be used instead.

  // Get a header
  $accept = $response->headers('Content-Type');

  // Set a header
  $response->headers('Content-Type', 'text/html');

  // Get all headers
  $headers = $response->headers();

  // Set multiple headers
  $response->headers(array('Content-Type' => 'text/html', 'Cache-Control' => 'no-cache'));
parse_cache_control
close

Response::parse_cache_control(array $cache_control)

Parses the Cache-Control header and returning an array representation of the Cache-Control header.

// Create the cache control header
$response->header['cache-control'] = 'max-age=3600, must-revalidate, public';

// Parse the cache control header
if ($cache_control = Request::parse_cache_control($response->header['cache-control']))
{
     // Cache-Control header was found
     $maxage = $cache_control['max-age'];
}
protocol
close

Response::protocol(string $protocol = NULL)

Gets or sets the HTTP protocol. The standard protocol to use is HTTP/1.1.

render
close

Response::render()

Renders the HTTP_Interaction to a string, producing

  • Protocol
  • Headers
  • Body
send_file
close

Response::send_file(string $filename, string $download = NULL, array $options = NULL)

Send file download as the response. All execution will be halted when this method is called! Use TRUE for the filename to send the current response as the file content. The third parameter allows the following options to be set:

Type Option Description Default Value
boolean inline Display inline instead of download FALSE
string mime_type Manual mime type Automatic
boolean delete Delete the file after sending FALSE

Download a file that already exists:

$request->send_file('media/packages/kohana.zip');

Download generated content as a file:

$request->response($content);
$request->send_file(TRUE, $filename);

No further processing can be done after this method is called!

send_headers
close

Response::send_headers()

Sends the response status and all set headers.

serialize
close

Response::serialize(array $to_serialize = array(0) )

Serializes the object to json - handy if you need to pass the response data to other systems

serialize
close

Response::serialize(array $to_serialize = array(0) )

Serializes the object to json - handy if you need to pass the response data to other systems

status
close

Response::status(integer $status = NULL)

Sets or gets the HTTP status from this response.

 // Set the HTTP status to 404 Not Found
 $response = Response::factory()
         ->status(404);

 // Get the current status
 $status = $response->status();
unserialize
close

Response::unserialize(string $string)

JSON encoded object

unserialize
close

Response::unserialize(string $string)

JSON encoded object

# _calculate_byte_range
close

Response::_calculate_byte_range(integer $size)

Calculates the byte range to use with send_file. If HTTP_RANGE doesn't exist then the complete byte range is returned

# _parse_byte_range
close

Response::_parse_byte_range()

Parse the byte ranges from the HTTP_RANGE header used for resumable downloads.

route  ? 
close

Routes are used to determine the controller and action for a requested URI. Every route generates a regular expression which is used to match a URI and a route. Routes may also contain keys which can be used to set the controller, action, and parameters.

Each will be translated to a regular expression using a default regular expression pattern. You can override the default pattern by providing a pattern for the key:

// This route will only match when <id> is a digit
Route::set('user', 'user/<action>/<id>', array('id' => '\d+'));

// This route will match when <path> is anything
Route::set('file', '<path>', array('path' => '.*'));

It is also possible to create optional segments by using parentheses in the URI definition:

// This is the standard default route, and no keys are required
Route::set('default', '(<controller>(/<action>(/<id>)))');

// This route only requires the <file> key
Route::set('file', '(<path>/)<file>(.<format>)', array('path' => '.*', 'format' => '\w+'));

Routes also provide a way to generate URIs (called "reverse routing"), which makes them an extremely powerful and flexible way to generate internal links.

properties
cache
close

Route::cache

Indicates whether routes are cached

default_action
close

Route::default_action

default action for all routes

default_protocol
close

Route::default_protocol

default protocol for all routes

localhosts
close

Route::localhosts

list of valid localhost entries

# _callback
close

Route::_callback

The callback method for routes

# _defaults
close

Route::_defaults

# _regex
close

Route::_regex

# _route_regex
close

Route::_route_regex

# _routes
close

Route::_routes

# _uri
close

Route::_uri

route URI

methods
all
close

Route::all()

Retrieves all named routes.

$routes = Route::all();
cache
close

Route::cache(boolean $save = bool FALSE)

Saves or loads the route cache. If your routes will remain the same for a long period of time, use this to reload the routes from the cache rather than redefining them on every page load.

if ( ! Route::cache())
{
    // Set routes here
    Route::cache(TRUE);
}
compile
close

Route::compile()

Returns the compiled regular expression for the route. This translates keys and optional groups to a proper PCRE regular expression.

$compiled = Route::compile(
   '<controller>(/<action>(/<id>))',
    array(
      'controller' => '[a-z]+',
      'id' => '\d+',
    )
);
defaults
close

Route::defaults(array $defaults = NULL)

Provides default values for keys when they are not present. The default action will always be "index" unless it is overloaded here.

$route->defaults(array(
    'controller' => 'welcome',
    'action'     => 'index'
));
get
close

Route::get(string $name)

Retrieves a named route.

$route = Route::get('default');
is_external
close

Route::is_external()

Returns whether this route is an external route to a remote controller.

matches
close

Route::matches(string $uri)

Tests if the route matches a given URI. A successful match will return all of the routed parameters as an array. A failed match will return boolean FALSE.

// Params: controller = users, action = edit, id = 10
$params = $route->matches('users/edit/10');

This method should almost always be used within an if/else block:

if ($params = $route->matches($uri))
{
    // Parse the parameters
}
name
close

Route::name(object $route)

Get the name of a route.

$name = Route::name($route)
set
close

Route::set(string $name, string $uri_callback = NULL, array $regex = NULL)

Stores a named route and returns it. The "action" will always be set to "index" if it is not defined.

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'welcome',
    ));
uri
close

Route::uri(array $params = NULL)

Generates a URI for the current route based on the parameters given.

// Using the "default" route: "users/profile/10"
$route->uri(array(
    'controller' => 'users',
    'action'     => 'profile',
    'id'         => '10'
));
url
close

Route::url(string $name, array $params = NULL, mixed $protocol = NULL)

Create a URL from a route name. This is a shortcut for:

echo URL::site(Route::get($name)->uri($params), $protocol);
security  ? 
close

Security helper class.

properties
token_name
close

Security::token_name

key name used for token storage

methods
check
close

Security::check(string $token)

Check that the given token matches the currently stored security token.

if (Security::check($token))
{
    // Pass
}
encode_php_tags
close

Security::encode_php_tags(string $str)

Encodes PHP tags in a string.

$str = Security::encode_php_tags($str);
strip_image_tags
close

Security::strip_image_tags(string $str)

Remove image tags from a string.

$str = Security::strip_image_tags($str);
token
close

Security::token(boolean $new = bool FALSE)

Generate and store a unique token which can be used to help prevent CSRF attacks.

$token = Security::token();

You can insert this token into your forms as a hidden field:

echo Form::hidden('csrf', Security::token());

And then check it when using Validation:

$array->rules('csrf', array(
    'not_empty'       => NULL,
    'Security::check' => NULL,
));

This provides a basic, but effective, method of preventing CSRF attacks.

session_cookie  ? 
close

Cookie-based session class.

properties
default
close

Session_Cookie::default

default session adapter

instances
close

Session_Cookie::instances

session instances

# _data
close

Session_Cookie::_data

session data

# _destroyed
close

Session_Cookie::_destroyed

session destroyed?

# _encrypted
close

Session_Cookie::_encrypted

encrypt session data?

# _lifetime
close

Session_Cookie::_lifetime

cookie lifetime

# _name
close

Session_Cookie::_name

cookie name

methods
as_array
close

Session_Cookie::as_array()

Returns the current session array. The returned array can also be assigned by reference.

// Get a copy of the current session data
$data = $session->as_array();

// Assign by reference for modification
$data =& $session->as_array();
bind
close

Session_Cookie::bind(string $key, mixed $value)

Set a variable by reference.

$session->bind('foo', $foo);
delete
close

Session_Cookie::delete(string $key)

Removes a variable in the session array.

$session->delete('foo');
destroy
close

Session_Cookie::destroy()

Completely destroy the current session.

$success = $session->destroy();
get
close

Session_Cookie::get(string $key, mixed $default = NULL)

Get a variable from the session array.

$foo = $session->get('foo');
get_once
close

Session_Cookie::get_once(string $key, mixed $default = NULL)

Get and delete a variable from the session array.

$bar = $session->get_once('bar');
id
close

Session_Cookie::id()

Get the current session id, if the session supports it.

$id = $session->id();

Not all session types have ids.

instance
close

Session_Cookie::instance(string $type = NULL, string $id = NULL)

Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.

$session = Session::instance();

Session::write will automatically be called when the request ends.

name
close

Session_Cookie::name()

Get the current session cookie name.

$name = $session->name();
read
close

Session_Cookie::read(string $id = NULL)

Loads existing session data.

$session->read();
regenerate
close

Session_Cookie::regenerate()

Generates a new session id and returns it.

$id = $session->regenerate();
set
close

Session_Cookie::set(string $key, mixed $value)

Set a variable in the session array.

$session->set('foo', 'bar');
write
close

Session_Cookie::write()

Sets the last_active timestamp and saves the session.

$session->write();

Any errors that occur during session writing will be logged, but not displayed, because sessions are written after output has been sent.

# _destroy
close

Session_Cookie::_destroy()

# _read
close

Session_Cookie::_read(string $id = NULL)

# _regenerate
close

Session_Cookie::_regenerate()

# _write
close

Session_Cookie::_write()

session_native  ? 
close

Native PHP session class.

properties
default
close

Session_Native::default

default session adapter

instances
close

Session_Native::instances

session instances

# _data
close

Session_Native::_data

session data

# _destroyed
close

Session_Native::_destroyed

session destroyed?

# _encrypted
close

Session_Native::_encrypted

encrypt session data?

# _lifetime
close

Session_Native::_lifetime

cookie lifetime

# _name
close

Session_Native::_name

cookie name

methods
as_array
close

Session_Native::as_array()

Returns the current session array. The returned array can also be assigned by reference.

// Get a copy of the current session data
$data = $session->as_array();

// Assign by reference for modification
$data =& $session->as_array();
bind
close

Session_Native::bind(string $key, mixed $value)

Set a variable by reference.

$session->bind('foo', $foo);
delete
close

Session_Native::delete(string $key)

Removes a variable in the session array.

$session->delete('foo');
destroy
close

Session_Native::destroy()

Completely destroy the current session.

$success = $session->destroy();
get
close

Session_Native::get(string $key, mixed $default = NULL)

Get a variable from the session array.

$foo = $session->get('foo');
get_once
close

Session_Native::get_once(string $key, mixed $default = NULL)

Get and delete a variable from the session array.

$bar = $session->get_once('bar');
id
close

Session_Native::id()

instance
close

Session_Native::instance(string $type = NULL, string $id = NULL)

Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.

$session = Session::instance();

Session::write will automatically be called when the request ends.

name
close

Session_Native::name()

Get the current session cookie name.

$name = $session->name();
read
close

Session_Native::read(string $id = NULL)

Loads existing session data.

$session->read();
regenerate
close

Session_Native::regenerate()

Generates a new session id and returns it.

$id = $session->regenerate();
set
close

Session_Native::set(string $key, mixed $value)

Set a variable in the session array.

$session->set('foo', 'bar');
write
close

Session_Native::write()

Sets the last_active timestamp and saves the session.

$session->write();

Any errors that occur during session writing will be logged, but not displayed, because sessions are written after output has been sent.

# _destroy
close

Session_Native::_destroy()

# _read
close

Session_Native::_read(string $id = NULL)

# _regenerate
close

Session_Native::_regenerate()

# _write
close

Session_Native::_write()

session  ? 
close
abstract

Base session class.

properties
default
close

Session::default

default session adapter

instances
close

Session::instances

session instances

# _data
close

Session::_data

session data

# _destroyed
close

Session::_destroyed

session destroyed?

# _encrypted
close

Session::_encrypted

encrypt session data?

# _lifetime
close

Session::_lifetime

cookie lifetime

# _name
close

Session::_name

cookie name

methods
as_array
close

Session::as_array()

Returns the current session array. The returned array can also be assigned by reference.

// Get a copy of the current session data
$data = $session->as_array();

// Assign by reference for modification
$data =& $session->as_array();
bind
close

Session::bind(string $key, mixed $value)

Set a variable by reference.

$session->bind('foo', $foo);
delete
close

Session::delete(string $key)

Removes a variable in the session array.

$session->delete('foo');
destroy
close

Session::destroy()

Completely destroy the current session.

$success = $session->destroy();
get
close

Session::get(string $key, mixed $default = NULL)

Get a variable from the session array.

$foo = $session->get('foo');
get_once
close

Session::get_once(string $key, mixed $default = NULL)

Get and delete a variable from the session array.

$bar = $session->get_once('bar');
id
close

Session::id()

Get the current session id, if the session supports it.

$id = $session->id();

Not all session types have ids.

instance
close

Session::instance(string $type = NULL, string $id = NULL)

Creates a singleton session of the given type. Some session types (native, database) also support restarting a session by passing a session id as the second parameter.

$session = Session::instance();

Session::write will automatically be called when the request ends.

name
close

Session::name()

Get the current session cookie name.

$name = $session->name();
read
close

Session::read(string $id = NULL)

Loads existing session data.

$session->read();
regenerate
close

Session::regenerate()

Generates a new session id and returns it.

$id = $session->regenerate();
set
close

Session::set(string $key, mixed $value)

Set a variable in the session array.

$session->set('foo', 'bar');
write
close

Session::write()

Sets the last_active timestamp and saves the session.

$session->write();

Any errors that occur during session writing will be logged, but not displayed, because sessions are written after output has been sent.

# _destroy
close

Session::_destroy()

Destroys the current session.

# _read
close

Session::_read(string $id = NULL)

Loads the raw session data string and returns it.

# _regenerate
close

Session::_regenerate()

Generate a new session id and return it.

# _write
close

Session::_write()

Writes the current session.

text  ? 
close

Text helper class. Provides simple methods for working with text.

properties
units
close

Text::units

number units and text equivalents

methods
alternate
close

Text::alternate()

Alternates between two or more strings.

echo Text::alternate('one', 'two'); // "one"
echo Text::alternate('one', 'two'); // "two"
echo Text::alternate('one', 'two'); // "one"

Note that using multiple iterations of different strings may produce unexpected results.

auto_link
close

Text::auto_link(string $text)

Converts text email addresses and anchors into links. Existing links will not be altered.

echo Text::auto_link($text);

This method is not foolproof since it uses regex to parse HTML.

auto_link_emails
close

Text::auto_link_emails(string $text)

Converts text email addresses into links. Existing links will not be altered.

echo Text::auto_link_emails($text);

This method is not foolproof since it uses regex to parse HTML.

auto_link_urls
close

Text::auto_link_urls(string $text)

Converts text anchors into links. Existing links will not be altered.

echo Text::auto_link_urls($text);

This method is not foolproof since it uses regex to parse HTML.

auto_p
close

Text::auto_p(string $str, boolean $br = bool TRUE)

Automatically applies "p" and "br" markup to text. Basically nl2br on steroids.

echo Text::auto_p($text);

This method is not foolproof since it uses regex to parse HTML.

bytes
close

Text::bytes(integer $bytes, string $force_unit = NULL, string $format = NULL, boolean $si = bool TRUE)

Returns human readable sizes. Based on original functions written by Aidan Lister and Quentin Zervaas.

echo Text::bytes(filesize($file));
censor
close

Text::censor(string $str, array $badwords, string $replacement = string(1) "#", boolean $replace_partial_words = bool TRUE)

Replaces the given words with a string.

// Displays "What the #####, man!"
echo Text::censor('What the frick, man!', array(
    'frick' => '#####',
));
limit_chars
close

Text::limit_chars(string $str, integer $limit = integer 100, string $end_char = NULL, boolean $preserve_words = bool FALSE)

Limits a phrase to a given number of characters.

$text = Text::limit_chars($text);
limit_words
close

Text::limit_words(string $str, integer $limit = integer 100, string $end_char = NULL)

Limits a phrase to a given number of words.

$text = Text::limit_words($text);
number
close

Text::number(integer $number)

Format a number to human-readable text.

// Display: one thousand and twenty-four
echo Text::number(1024);

// Display: five million, six hundred and thirty-two
echo Text::number(5000632);
random
close

Text::random(string $type = NULL, integer $length = integer 8)

Generates a random string of a given type and length.

$str = Text::random(); // 8 character random string

The following types are supported:

alnum
Upper and lower case a-z, 0-9 (default)
alpha
Upper and lower case a-z
hexdec
Hexadecimal characters a-f, 0-9
distinct
Uppercase characters and numbers that cannot be confused

You can also create a custom type by providing the "pool" of characters as the type.

reduce_slashes
close

Text::reduce_slashes(string $str)

Reduces multiple slashes in a string to single slashes.

$str = Text::reduce_slashes('foo//bar/baz'); // "foo/bar/baz"
similar
close

Text::similar(array $words)

Finds the text that is similar between a set of words.

$match = Text::similar(array('fred', 'fran', 'free'); // "fr"
widont
close

Text::widont(string $str)

Prevents widow words by inserting a non-breaking space between the last two words.

echo Text::widont($text);
# _auto_link_emails_callback
close

Text::_auto_link_emails_callback()

# _auto_link_urls_callback1
close

Text::_auto_link_urls_callback1()

# _auto_link_urls_callback2
close

Text::_auto_link_urls_callback2()

upload  ? 
close

Upload helper class for working with uploaded files and Validation.

$array = Validation::factory($_FILES);

Remember to define your form with "enctype=multipart/form-data" or file uploading will not work!

The following configuration properties can be set:

properties
default_directory
close

Upload::default_directory

default upload directory

remove_spaces
close

Upload::remove_spaces

remove spaces in uploaded files

methods
not_empty
close

Upload::not_empty(array $file)

Tests if a successful upload has been made.

$array->rule('file', 'Upload::not_empty');
save
close

Upload::save(array $file, string $filename = NULL, string $directory = NULL, integer $chmod = integer 420)

Save an uploaded file to a new location. If no filename is provided, the original filename will be used, with a unique prefix added.

This method should be used after validating the $_FILES array:

if ($array->check())
{
    // Upload is valid, save it
    Upload::save($_FILES['file']);
}
size
close

Upload::size(array $file, string $size)

Validation rule to test if an uploaded file is allowed by file size. File sizes are defined as: SB, where S is the size (1, 8.5, 300, etc.) and B is the byte unit (K, MiB, GB, etc.). All valid byte units are defined in Num::$byte_units

$array->rule('file', 'Upload::size', array('1M'))
$array->rule('file', 'Upload::size', array('2.5KiB'))
type
close

Upload::type(array $file, array $allowed)

Test if an uploaded file is an allowed file type, by extension.

$array->rule('file', 'Upload::type', array(array('jpg', 'png', 'gif')));
valid
close

Upload::valid(array $file)

Tests if upload data is valid, even if no file was uploaded. If you do require a file to be uploaded, add the Upload::not_empty rule before this rule.

$array->rule('file', 'Upload::valid')
url  ? 
close

URL helper class.

methods
base
close

URL::base(mixed $protocol = NULL, boolean $index = bool FALSE)

Gets the base URL to the application. To specify a protocol, provide the protocol as a string or request object. If a protocol is used, a complete URL will be generated using the $_SERVER['HTTP_HOST'] variable.

// Absolute URL path with no host or protocol
echo URL::base();

// Absolute URL path with host, https protocol and index.php if set
echo URL::base('https', TRUE);

// Absolute URL path with host and protocol from $request
echo URL::base($request);
query
close

URL::query(array $params = NULL, boolean $use_get = bool TRUE)

Merges the current GET parameters with an array of new or overloaded parameters and returns the resulting query string.

// Returns "?sort=title&limit=10" combined with any existing GET values
$query = URL::query(array('sort' => 'title', 'limit' => 10));

Typically you would use this when you are sorting query results, or something similar.

Parameters with a NULL value are left out.

site
close

URL::site(string $uri = string(0) "", mixed $protocol = NULL, boolean $index = bool TRUE)

Fetches an absolute site URL based on a URI segment.

echo URL::site('foo/bar');
title
close

URL::title(string $title, string $separator = string(1) "-", boolean $ascii_only = bool FALSE)

Convert a phrase to a URL-safe title.

echo URL::title('My Blog Post'); // "my-blog-post"
utf8  ? 
close

A port of phputf8 to a unified set of files. Provides multi-byte aware replacement string functions.

For UTF-8 support to work correctly, the following requirements must be met:

  • PCRE needs to be compiled with UTF-8 support (--enable-utf8)
  • Support for Unicode properties is highly recommended (--enable-unicode-properties)
  • UTF-8 conversion will be much more reliable if the iconv extension is loaded
  • The mbstring extension is highly recommended, but must not be overloading string functions

This file is licensed differently from the rest of Kohana. As a port of phputf8, this file is released under the LGPL.

properties
called
close

UTF8::called

List of called methods that have had their required file included.

server_utf8
close

UTF8::server_utf8

Does the server support UTF-8 natively?

methods
clean
close

UTF8::clean(mixed $var, string $charset = NULL)

Recursively cleans arrays, objects, and strings. Removes ASCII control codes and converts to the requested charset while silently discarding incompatible characters.

UTF8::clean($_GET); // Clean GET data

This method requires Iconv

from_unicode
close

UTF8::from_unicode(array $arr)

Takes an array of ints representing the Unicode characters and returns a UTF-8 string. Astral planes are supported i.e. the ints in the input can be > 0xFFFF. Occurrances of the BOM are ignored. Surrogates are not allowed.

$str = UTF8::to_unicode($array);

The Original Code is Mozilla Communicator client code. The Initial Developer of the Original Code is Netscape Communications Corporation. Portions created by the Initial Developer are Copyright (C) 1998 the Initial Developer. Ported to PHP by Henri Sivonen hsivonen@iki.fi, see http://hsivonen.iki.fi/php-utf8/ Slight modifications to fit with phputf8 library by Harry Fuecks hfuecks@gmail.com.

is_ascii
close

UTF8::is_ascii(mixed $str)

Tests whether a string contains only 7-bit ASCII bytes. This is used to determine when to use native functions or UTF-8 functions.

$ascii = UTF8::is_ascii($str);
ltrim
close

UTF8::ltrim(string $str, string $charlist = NULL)

Strips whitespace (or other UTF-8 characters) from the beginning of a string. This is a UTF8-aware version of ltrim.

$str = UTF8::ltrim($str);
ord
close

UTF8::ord(string $chr)

Returns the unicode ordinal for a character. This is a UTF8-aware version of ord.

$digit = UTF8::ord($character);
rtrim
close

UTF8::rtrim(string $str, string $charlist = NULL)

Strips whitespace (or other UTF-8 characters) from the end of a string. This is a UTF8-aware version of rtrim.

$str = UTF8::rtrim($str);
str_ireplace
close

UTF8::str_ireplace(string|array $search, string|array $replace, string|array $str, integer $count = NULL)

Returns a string or an array with all occurrences of search in subject (ignoring case) and replaced with the given replace value. This is a UTF8-aware version of str_ireplace.

This function is very slow compared to the native version. Avoid using it when possible.

str_pad
close

UTF8::str_pad(string $str, integer $final_str_length, string $pad_str = string(1) " ", string $pad_type = integer 1)

Pads a UTF-8 string to a certain length with another string. This is a UTF8-aware version of str_pad.

$str = UTF8::str_pad($str, $length);
str_split
close

UTF8::str_split(string $str, integer $split_length = integer 1)

Converts a UTF-8 string to an array. This is a UTF8-aware version of str_split.

$array = UTF8::str_split($str);
strcasecmp
close

UTF8::strcasecmp(string $str1, string $str2)

Case-insensitive UTF-8 string comparison. This is a UTF8-aware version of strcasecmp.

$compare = UTF8::strcasecmp($str1, $str2);
strcspn
close

UTF8::strcspn(string $str, string $mask, integer $offset = NULL, integer $length = NULL)

Finds the length of the initial segment not matching mask. This is a UTF8-aware version of strcspn.

$found = UTF8::strcspn($str, $mask);
strip_ascii_ctrl
close

UTF8::strip_ascii_ctrl(string $str)

Strips out device control codes in the ASCII range.

$str = UTF8::strip_ascii_ctrl($str);
strip_non_ascii
close

UTF8::strip_non_ascii(string $str)

Strips out all non-7bit ASCII bytes.

$str = UTF8::strip_non_ascii($str);
stristr
close

UTF8::stristr(string $str, string $search)

Case-insenstive UTF-8 version of strstr. Returns all of input string from the first occurrence of needle to the end. This is a UTF8-aware version of stristr.

$found = UTF8::stristr($str, $search);
strlen
close

UTF8::strlen(string $str)

Returns the length of the given string. This is a UTF8-aware version of strlen.

$length = UTF8::strlen($str);
strpos
close

UTF8::strpos(string $str, string $search, integer $offset = integer 0)

Finds position of first occurrence of a UTF-8 string. This is a UTF8-aware version of strpos.

$position = UTF8::strpos($str, $search);
strrev
close

UTF8::strrev(string $str)

Reverses a UTF-8 string. This is a UTF8-aware version of strrev.

$str = UTF8::strrev($str);
strrpos
close

UTF8::strrpos(string $str, string $search, integer $offset = integer 0)

Finds position of last occurrence of a char in a UTF-8 string. This is a UTF8-aware version of strrpos.

$position = UTF8::strrpos($str, $search);
strspn
close

UTF8::strspn(string $str, string $mask, integer $offset = NULL, integer $length = NULL)

Finds the length of the initial segment matching mask. This is a UTF8-aware version of strspn.

$found = UTF8::strspn($str, $mask);
strtolower
close

UTF8::strtolower(string $str)

Makes a UTF-8 string lowercase. This is a UTF8-aware version of strtolower.

$str = UTF8::strtolower($str);
strtoupper
close

UTF8::strtoupper(string $str)

Makes a UTF-8 string uppercase. This is a UTF8-aware version of strtoupper.

substr
close

UTF8::substr(string $str, integer $offset, integer $length = NULL)

Returns part of a UTF-8 string. This is a UTF8-aware version of substr.

$sub = UTF8::substr($str, $offset);
substr_replace
close

UTF8::substr_replace(string $str, string $replacement, integer $offset, $length = NULL)

Replaces text within a portion of a UTF-8 string. This is a UTF8-aware version of substr_replace.

$str = UTF8::substr_replace($str, $replacement, $offset);
to_unicode
close

UTF8::to_unicode(string $str)

Takes an UTF-8 string and returns an array of ints representing the Unicode characters. Astral planes are supported i.e. the ints in the output can be > 0xFFFF. Occurrences of the BOM are ignored. Surrogates are not allowed.

$array = UTF8::to_unicode($str);

The Original Code is Mozilla Communicator client code. The Initial Developer of the Original Code is Netscape Communications Corporation. Portions created by the Initial Developer are Copyright (C) 1998 the Initial Developer. Ported to PHP by Henri Sivonen hsivonen@iki.fi, see http://hsivonen.iki.fi/php-utf8/ Slight modifications to fit with phputf8 library by Harry Fuecks hfuecks@gmail.com

transliterate_to_ascii
close

UTF8::transliterate_to_ascii(string $str, integer $case = integer 0)

Replaces special/accented UTF-8 characters by ASCII-7 "equivalents".

$ascii = UTF8::transliterate_to_ascii($utf8);
trim
close

UTF8::trim(string $str, string $charlist = NULL)

Strips whitespace (or other UTF-8 characters) from the beginning and end of a string. This is a UTF8-aware version of trim.

$str = UTF8::trim($str);
ucfirst
close

UTF8::ucfirst(string $str)

Makes a UTF-8 string's first character uppercase. This is a UTF8-aware version of ucfirst.

$str = UTF8::ucfirst($str);
ucwords
close

UTF8::ucwords(string $str)

Makes the first character of every word in a UTF-8 string uppercase. This is a UTF8-aware version of ucwords.

$str = UTF8::ucwords($str);
valid  ? 
close

Validation rules.

methods
alpha
close

Valid::alpha(string $str, boolean $utf8 = bool FALSE)

Checks whether a string consists of alphabetical characters only.

alpha_dash
close

Valid::alpha_dash(string $str, boolean $utf8 = bool FALSE)

Checks whether a string consists of alphabetical characters, numbers, underscores and dashes only.

alpha_numeric
close

Valid::alpha_numeric(string $str, boolean $utf8 = bool FALSE)

Checks whether a string consists of alphabetical characters and numbers only.

color
close

Valid::color(string $str)

Checks if a string is a proper hexadecimal HTML color value. The validation is quite flexible as it does not require an initial "#" and also allows for the short notation using only three instead of six hexadecimal characters.

credit_card
close

Valid::credit_card(integer $number, string|array $type = NULL)

Validates a credit card number, with a Luhn check if possible.

date
close

Valid::date(string $str)

Tests if a string is a valid date string.

decimal
close

Valid::decimal(string $str, integer $places = integer 2, integer $digits = NULL)

Checks if a string is a proper decimal format. Optionally, a specific number of digits can be checked too.

digit
close

Valid::digit(string $str, boolean $utf8 = bool FALSE)

Checks whether a string consists of digits only (no dots or dashes).

email
close

Valid::email(string $email, boolean $strict = bool FALSE)

Check an email address for correct format.

email_domain
close

Valid::email_domain(string $email)

Validate the domain of an email address by checking if the domain has a valid MX record.

equals
close

Valid::equals(string $value, string $required)

Checks that a field is exactly the value required.

exact_length
close

Valid::exact_length(string $value, integer $length)

Checks that a field is exactly the right length.

ip
close

Valid::ip(string $ip, boolean $allow_private = bool TRUE)

Validate an IP.

luhn
close

Valid::luhn(string $number)

Validate a number against the Luhn (mod10) formula.

matches
close

Valid::matches(array $array, string $field, string $match)

Checks if a field matches the value of another field.

max_length
close

Valid::max_length(string $value, integer $length)

Checks that a field is short enough.

min_length
close

Valid::min_length(string $value, integer $length)

Checks that a field is long enough.

not_empty
close

Valid::not_empty()

Checks if a field is not empty.

numeric
close

Valid::numeric(string $str)

Checks whether a string is a valid number (negative and decimal numbers allowed).

Uses {@link http://www.php.net/manual/en/function.localeconv.php locale conversion} to allow decimal point to be locale specific.

phone
close

Valid::phone(string $number, $lengths = NULL)

Checks if a phone number is valid.

range
close

Valid::range(string $number, integer $min, integer $max)

Tests if a number is within a range.

regex
close

Valid::regex(string $value, string $expression)

Checks a field against a regular expression.

url
close

Valid::url(string $url)

Validate a URL.

validation  ? 
close

Array and variable validation.

properties
# _bound
close

Validation::_bound

# _empty_rules
close

Validation::_empty_rules

# _errors
close

Validation::_errors

# _labels
close

Validation::_labels

# _rules
close

Validation::_rules

methods
append
close

Validation::append()

append
close

Validation::append()

as_array
close

Validation::as_array()

Returns the array representation of the current object.

asort
close

Validation::asort()

asort
close

Validation::asort()

bind
close

Validation::bind(string $key, mixed $value = NULL)

Bind a value to a parameter definition.

// This allows you to use :model in the parameter definition of rules
$validation->bind(':model', $model)
    ->rule('status', 'valid_status', array(':model'));
check
close

Validation::check()

Executes all validation rules. This should typically be called within an if/else block.

if ($validation->check())
{
     // The data is valid, do something here
}
copy
close

Validation::copy(array $array)

Copies the current rule to a new array.

$copy = $array->copy($new_data);
count
close

Validation::count()

count
close

Validation::count()

error
close

Validation::error(string $field, string $error, $params = NULL)

Add an error to a field.

errors
close

Validation::errors(string $file = NULL, mixed $translate = bool TRUE)

Returns the error messages. If no file is specified, the error message will be the name of the rule that failed. When a file is specified, the message will be loaded from "field/rule", or if no rule-specific message exists, "field/default" will be used. If neither is set, the returned message will be "file/field/rule".

By default all messages are translated using the default language. A string can be used as the second parameter to specified the language that the message was written in.

// Get errors from messages/forms/login.php
$errors = $Validation->errors('forms/login');
exchangeArray
close

Validation::exchangeArray()

exchangeArray
close

Validation::exchangeArray()

factory
close

Validation::factory(array $array)

Creates a new Validation instance.

getArrayCopy
close

Validation::getArrayCopy()

getArrayCopy
close

Validation::getArrayCopy()

getFlags
close

Validation::getFlags()

getFlags
close

Validation::getFlags()

getIterator
close

Validation::getIterator()

getIterator
close

Validation::getIterator()

getIteratorClass
close

Validation::getIteratorClass()

getIteratorClass
close

Validation::getIteratorClass()

ksort
close

Validation::ksort()

ksort
close

Validation::ksort()

label
close

Validation::label(string $field, string $label)

Sets or overwrites the label name for a field.

labels
close

Validation::labels(array $labels)

Sets labels using an array.

natcasesort
close

Validation::natcasesort()

natcasesort
close

Validation::natcasesort()

natsort
close

Validation::natsort()

natsort
close

Validation::natsort()

offsetExists
close

Validation::offsetExists()

offsetExists
close

Validation::offsetExists()

offsetGet
close

Validation::offsetGet()

offsetGet
close

Validation::offsetGet()

offsetSet
close

Validation::offsetSet()

offsetSet
close

Validation::offsetSet()

offsetUnset
close

Validation::offsetUnset()

offsetUnset
close

Validation::offsetUnset()

rule
close

Validation::rule(string $field, callback $rule, array $params = NULL)

Overwrites or appends rules to a field. Each rule will be executed once. All rules must be string names of functions method names. Parameters must match the parameters of the callback function exactly

Aliases you can use in callback parameters: - :validation - the validation object - :field - the field name - :value - the value of the field

// The "username" must not be empty and have a minimum length of 4
$validation->rule('username', 'not_empty')
           ->rule('username', 'min_length', array('username', 4));

// The "password" field must match the "password_repeat" field
$validation->rule('password', 'matches', array(':validation', 'password', 'password_repeat'));
rules
close

Validation::rules(string $field, array $rules)

Add rules using an array.

setFlags
close

Validation::setFlags()

setFlags
close

Validation::setFlags()

setIteratorClass
close

Validation::setIteratorClass()

setIteratorClass
close

Validation::setIteratorClass()

uasort
close

Validation::uasort()

uasort
close

Validation::uasort()

uksort
close

Validation::uksort()

uksort
close

Validation::uksort()

view  ? 
close

Acts as an object wrapper for HTML pages with embedded PHP, called "views". Variables can be assigned with the view object and referenced locally within the view.

properties
# _data
close

View::_data

# _file
close

View::_file

# _global_data
close

View::_global_data

methods
bind
close

View::bind(string $key, mixed $value)

Assigns a value by reference. The benefit of binding is that values can be altered without re-setting them. It is also possible to bind variables before they have values. Assigned values will be available as a variable within the view file:

// This reference can be accessed as $ref within the view
$view->bind('ref', $bar);
bind_global
close

View::bind_global(string $key, mixed $value)

Assigns a global variable by reference, similar to View::bind, except that the variable will be accessible to all views.

View::bind_global($key, $value);
factory
close

View::factory(string $file = NULL, array $data = NULL)

Returns a new View object. If you do not define the "file" parameter, you must call View::set_filename.

$view = View::factory($file);
render
close

View::render(string $file = NULL)

Renders the view object to a string. Global and local data are merged and extracted to create local variables within the view file.

$output = $view->render();

Global variables with the same key name as local variables will be overwritten by the local variable.

set
close

View::set(string $key, mixed $value = NULL)

Assigns a variable by name. Assigned values will be available as a variable within the view file:

// This value can be accessed as $foo within the view
$view->set('foo', 'my value');

You can also use an array to set several values at once:

// Create the values $food and $beverage in the view
$view->set(array('food' => 'bread', 'beverage' => 'water'));
set_filename
close

View::set_filename(string $file)

Sets the view filename.

$view->set_filename($file);
set_global
close

View::set_global(string $key, mixed $value = NULL)

Sets a global variable, similar to View::set, except that the variable will be accessible to all views.

View::set_global($name, $value);
# capture
close

View::capture(string $kohana_view_filename, array $kohana_view_data)

Captures the output that is generated when a view is included. The view data will be extracted to make local variables. This method is static to prevent object scope resolution.

$output = View::capture($file, $data);
Execution time: 0.171 seconds — Memory: 5540 kb
Data loaded from cache
Invalidate cache