-
Notifications
You must be signed in to change notification settings - Fork 194
Helper Data
Name | Path |
---|---|
Data Helper | /application/helpers/data_helper.php |
These methods help manipulate data (typically strings) for use in the application.
$this->load->helper('data_helper');
Will decode a previously encoded string.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | string | N/A | Yes | The string to decode |
$string = decodeValue($string);
Inspects the URL and looks at the last segment to extract a possible page number from.
// URL /marks/today/5
$page = findPage();
// $page = 5
// URL /marks/2014
$page = findPage();
// $page = 1
Attempts to find the timestamp to use for start and finish date lookups.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$start | string | N/A | Yes | The date or timeframe to find the start date from. |
$finish | string | null | No | The finish date or timeframe. If not send the function will figure it out for you. |
// Returns the correct timestamps
$dates = findStartFinish('4 days ago', 'today');
// Returns start as first day of the year and finish as last day of the year
$dates = findStartFinish(2013);
Returns an array of formatted errors.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$errors | Mixed | N/A | Yes | Either an array of errors or an error number. |
// Return array with key of 100 and message of Security token is invalid.
$errors = formatErrors(100);
// Returns array as it was sent
$errors = formatErrors(array(102 => array('email' => 'Email address is invalid')));
Takes a string and returns a valid slug to be used for lookups and within a url.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | String | N/A | Yes | The string to used to create a slug. |
// Return my-slug
$errors = formatErrors('My Slug!');
Used to return a nice time when an item was created. Instead of showing the exact datetime of an item it will return something like '10 days ago'.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$date | Mixed | N/A | Yes | A string of a date, data or datetime. |
// Returns 1 day ago (assuming today is 2014-01-30)
$nice_time = generateTimeSpan('2014-01-29');
Will simply return the last JSON error if any after parsing a JSON document. If no error it will return false.
$json = json_decode($file);
$json_error = getLastJsonError();
if ($json_error === false) {
// do something
}
else {
// Log exception
}
Pass a URL to this function and it will return an array giving you the domain, path and key (md5 hash of domain).
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | String | N/A | Yes | The URL to extract information from. |
// Returns array of domain: nilai.co, path: , key: ea494e43dd071dc289fbe07c5d05f574
$smart_info = getSmartLabelInfo('http://nilail.co');
// Returns array of domain: nilai.co, path: /marks, key: ea494e43dd071dc289fbe07c5d05f574
$smart_info = getSmartLabelInfo('nilail.co/marks');
// Returns array of domain: nilai.co, path: /search, key: ea494e43dd071dc289fbe07c5d05f574
$smart_info = getSmartLabelInfo('http://www.nilail.co/search');
Returns the words attached to hashmarks in a string.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | String | N/A | Yes | The string to extract tags from. |
// Returns array of 0: hash, 1: tag, 2: jeff
$tags = getSmartLabelInfo('This is my string. #hash #tag #jeff');
Removes any unwanted tags from the string, replaces new lines with breaks and decodes the string if already encoded.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | string | N/A | Yes | The string to purify |
$string = purifyHTML($string);
Takes a string, replaces and underscores or dashes with spaces and captilized each word.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | string | N/A | Yes | The string to ready |
// Returns About Us
$string = readEasy('about_us');
Purifies a domain name before getting put into the DB. Basically strips the protocol off.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$domain | string | N/A | Yes | The domain to ready |
// Returns www.google.com
$string = readyDomain('http://www.google.com');
Takes a string and makes sure it starts with a slash and does NOT end with a slash.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | N/A | Yes | The url to update |
// Returns /test/about-us
$string = readyDomain('test/about-us/');
Sort of like PHP's strip_tags
method except it works in reverse. You specify the tags to remove not keep.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$str | string | N/A | Yes | The string to strip tags from. |
$tags | array | N/A | Yes | An array of tags to strip from the submitted string. |
$string = stripTags($string, array('font','iframe','script'));